-1

I used following command to create a nginx container.

$ docker run -it -d --name test-nginx -p 8090:8091 nginx

and it seems to be up and running fine

$ docker ps
CONTAINER ID   IMAGE                               COMMAND                  CREATED             STATUS             PORTS                                                                                                                                                                                                                                              NAMES
e36f30ce7854   nginx                               "/docker-entrypoint.…"   About an hour ago   Up About an hour   80/tcp, 0.0.0.0:8090->8091/tcp, :::8090->8091/tcp                                                                                                                                                                        test-nginx

But I'm not able to access the container via browser or curl command. I get the following error.

$ curl localhost
curl: (7) Failed connect to localhost:80; Connection refused
$ curl localhost:8090
curl: (56) Recv failure: Connection reset by peer
curl localhost:8091
curl: (7) Failed connect to localhost:8091; Connection refused
$ curl 10.57.8.115
curl: (7) Failed connect to 10.57.8.115:80; Connection refused
$ curl 10.57.8.115:8090
curl: (7) Failed connect to 10.57.8.115:8090; Connection refused
$ curl 10.57.8.115:8091
curl: (7) Failed connect to 10.57.8.115:8091; Connection refused

Could anyone please help me what is the issue and when I do

$ curl localhost:8090

It gives the following error?

curl: (56) Recv failure: Connection reset by peer
Nitin Kumar
  • 59
  • 1
  • 6

1 Answers1

1

nginx listens on port 80 within the container, so that is the port you need to expose on the host. You are exposing port 8091. So your command should be:

docker run -it -d --name test-nginx -p 8091:80 nginx

to expose container port 80 on local host port 8091. Your curl command should then run successfully:

$ curl -I localhost:8091
HTTP/1.1 200 OK
Server: nginx/1.23.1
Date: Fri, 07 Oct 2022 07:29:43 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 19 Jul 2022 14:05:27 GMT
Connection: keep-alive
ETag: "62d6ba27-267"
Accept-Ranges: bytes
JohnXF
  • 972
  • 9
  • 22