我使用以下命令创建了一个nginx容器。$ docker run -it -d --name test-nginx -p 8090:8091 nginx
看起来一切正常
$ 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
但是我不能通过浏览器或curl命令访问容器。我得到以下错误。
$ 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
有谁能帮我解决问题吗?什么时候解决?
$ curl localhost:8090
它给出以下错误?
curl: (56) Recv failure: Connection reset by peer
1条答案
按热度按时间7hiiyaii1#
nginx监听容器中的端口80,因此这是您需要在主机上公开的端口。您公开的是端口8091。因此您的命令应该是:
以公开本地主机端口8091上的容器端口80。然后,您的
curl
命令应该会成功运行: