Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

docker-machine: Can't access container's web server from host

I just installed Docker with Docker-Toolbox on my Mac using homebrew: install docker with homebrew

After creating and configuring a Container with Rails, Postgres and starting docker-compose up everything looks fine but i can't access the webserver from host.

The output of

$ docker-compose up

dummy_1    | I, [2016-03-30T14:55:53.130639 #6]  INFO -- : listening on addr=0.0.0.0:8000 fd=10

When i type in Google Chrome the url http://0.0.0.0:8000/ i get

This site can’t be reached

0.0.0.0 refused to connect.
ERR_CONNECTION_REFUSED

So i tried

$ docker-machine env dummy

with the following output:

export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/choi/.docker/machine/machines/dummy"
export DOCKER_MACHINE_NAME="dummy"

When i try in Chrome http://192.168.99.100:2376 i get a blank file downloaded. Why is it so? I expect the default greeting page of my Rails App.

question from:https://stackoverflow.com/questions/36312750/docker-machine-cant-access-containers-web-server-from-host

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

192.168.99.100 is the IP of your Docker host, in this instance. You need to expose the port of your container and then you will be able to connect to it from the outside world.

I'm not familiar with Docker Compose, but the log you have posted suggests port 8000 is exposed. Try, therefore, http://192.168.99.100:8000.

(The reason http://192.168.99.100:2376 doesn't work is because that's the address and port of the Docker daemon itself, which isn't HTTP-based. As for 0.0.0.0: This is the address which your web server is listening on inside the container and equates to all external connections therein. However, without any ports exposed, there's no way in!)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...