在 Docker 容器之外无法访问 nginx

nginx not accessible outside of Docker container

这一定是个简单的问题。我正在使用 boot2docker。如果我通过 ssh 进入 boot2docker:

docker@boot2docker:~$ docker ps
CONTAINER ID        IMAGE                         COMMAND              CREATED             STATUS              PORTS                          NAMES
89ec1492d7c7        mycontainer:latest   "/bin/sh -c nginx"   35 seconds ago      Up 35 seconds       80/tcp, 0.0.0.0:80->1000/tcp   desperate_mestorf

然后卷曲:

docker@boot2docker:~$ curl localhost:1000 curl: (7) Failed connect to
localhost:1000; Connection refused 
docker@boot2docker:~$ curl
localhost:80 curl: (56) Recv failure: Connection reset by peer

在端口 80 上卷曲只是为了确保我不会发疯。然后我连接到我的容器 bash:

docker@boot2docker:~$ docker exec -i -t 89ec1492d7c7 bash
root@89ec1492d7c7:/srv/www# curl localhost
<!DOCTYPE html><html><head><link rel="stylesheet" href="/main.css"></head><body><h1>Welcome to Harp.</h1><h3>This is yours to own. Enjoy.</h3></body></html>root

轰!它有效,甚至在保留默认端口 80 的同时尝试了此操作。真正奇怪的是我的盒子上还有其他我可以使用的容器。甚至在我的 boot2docker VM 之外(我只是用它来消除等式中的另一件事)。这一定很简单吧?

只是 Unable to connect to Docker Nginx build

中的另一个相同问题

这里是连接nginxdocker容器服务的方式:

docker ps            # confirm nginx is running, which you have done.
docker port desperate_mestorf  # get the ports, for example: 80/tcp, 0.0.0.0:80->1000/tcp
boot2docker ip       # get the IP address, for example: 192.168.59.103

现在,您应该可以连接到:

http://192.168.59.103:1000