Unable to connect to Docker Nginx build

偶尔善良 提交于 2019-12-11 09:45:24

问题


I am trying to host a simple static site using the Docker Nginx Image from Dockerhub: https://registry.hub.docker.com/_/nginx/

A note on my setup, I am using boot2docker on OSX.

I have followed the instructions and even I cannot connect to the running container:

MacBook-Pro:LifeIT-war-games-frontend ryan$ docker build -t wargames-front-end .
Sending build context to Docker daemon 813.6 kB
Sending build context to Docker daemon 
Step 0 : FROM nginx
 ---> 42a3cf88f3f0
Step 1 : COPY app /usr/share/nginx/html
 ---> Using cache
 ---> 61402e6eb300
Successfully built 61402e6eb300
MacBook-Pro:LifeIT-war-games-frontend ryan$ docker run --name wargames-front-end -d -p 8080:8080 wargames-front-end
9f7daa48a25bdc09e4398fed5d846dd0eb4ee234bcfe89744268bee3e5706e54
MacBook-Pro:LifeIT-war-games-frontend ryan$ curl localhost:8080
curl: (52) Empty reply from server
MacBook-Pro:LifeIT-war-games-frontend ryan$ docker ps -a
CONTAINER ID        IMAGE                       COMMAND                CREATED             STATUS              PORTS                                     NAMES
9f7daa48a25b        wargames-front-end:latest   "nginx -g 'daemon of   3 minutes ago       Up 3 minutes        80/tcp, 0.0.0.0:8080->8080/tcp, 443/tcp   wargames-front-end   

回答1:


Instead of localhost, use boot2docker ip. First do boot2docker ip and use that ip: <your-b2d-ip>:8080. Also you need to make sure you forwarded your port 8080 in VirtualBox for boot2docker.




回答2:


Here is the way to connect nginx docker container service:

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

So now, you should be fine to connect to:

http://192.168.59.103:8080
https://192.168.59.103:8080



回答3:


Here's how I got it to work.

docker kill wargames-front-end
docker rm wargames-front-end
docker run --name wargames-front-end -d -p 8080:80 wargames-front-end

Then I went to my virtualbox and setup these settings:



来源:https://stackoverflow.com/questions/30202626/unable-to-connect-to-docker-nginx-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!