NGINX docker container cannot be accessed in the web browser

Viewed 755

I have deployed this docker container.

docker container run -d -p 8080:80 --name my-nginx2 --network my-net nginx:latest

When I do a curl localhost:8080, I am able to access it. However, when I type in my <public-address>:8080 it is not working. I cannot access it on the web browser.

I am running a red hat 8 ec2 instance on AWS. My security group looks like this. I am not sure if this should be something related with SG.

enter image description here

Let me know if you have any questions.
Thanks.

1 Answers

According to the image you shared, you are only allowing traffic on ports 80 and 22;

When you execute the docker run command with the -p :8080:80 option, you are basically telling your instance to listen on 8080 and forward the traffic to the container on port 80;

You have two options:
Start the container using the -p 80:80 option, hence port 80 is already allowed, then try to access your web-app in the browser at <instance-external-ip-address>:80

The second option is to add a firewall rule to allow ingress on port 8080 and then access your web-app in the browser at <instance-external-ip-address>:8080

Related