nginx无法在Docker容器外部访问

时间:2015-05-12 21:14:08

标签: nginx docker

这必须是一个简单的问题。我正在使用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之外(我只是用了另外一件事)。这一定很简单吗?

1 个答案:

答案 0 :(得分:1)

Unable to connect to Docker Nginx build

中的另一个问题

以下是连接nginx docker容器服务的方法:

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