I'm running under boot2docker 1.3.1.
I have a Docker container running a web server via uwsgi --http :8080
.
If I attach to the container I can browse the web site using lynx http://127.0.0.1:8080
so I know the server is working.
I ran my container with:
$ docker run -itP --expose 8080 uwsgi_app:0.2
It has the following details:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5248ad86596d uwsgi_app:0.2 "bash" 11 minutes ago Up 11 minutes 0.0.0.0:49159->8080/tcp cocky_hypatia
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' 5248ad86596d
172.17.0.107
I thought I could access that web site from my host by going to http://172.17.0.107:49159
.
This does not work. I just see 'connecting...' in Chrome, getting nowhere.
What am I doing wrong?
Extending Anentropic's answer:
boot2docker
is the old app for Mac and Windows,docker-machine
is the new one.Firstly, list your machines:
Then select one of the machines (the default one is called
default
) and:[EDIT: original version was ignoring the -P in question]
If you want to get to the containers without having to 'publish' the port (which changes its number) there is a good run-through here.
The key is this line:
which tells the Mac how to route to the private network inside the VirtualBox VM that the Docker containers are on.
Boot2docker is outdated, but you may still have this problem on Docker for Windows or Mac, even though the same container works on Linux. One symptom is that trying to access a page on the server inside the container gives the error "didn't send any data" as opposed to "could not connect."
If so, it may be because on Win/Mac the container host has its own IP, it's not localhost as it is on linux. Try running Django on IP 0.0.0.0, meaning accept connections from all IPs, like this:
Alternatively, if you need to make sure the server only responds to local requests (such as from your local proxy like nginx, apache, or gunicorn) you can use the host IP returned by
hostname -i
.And make sure you are using the
-p
port forwarding option correctly in thedocker run
command.Assuming all is well, you should be able to access your server at http://localhost in a browser running on the host machine.
Ok, stupid me, I found the answer in the docs for boot2docker https://docs.docker.com/installation/mac/#container-port-redirection
I needed to use the ip address of the boot2docker vm, rather than the ip of the container, i.e.
and I am able to browse my site from the host at
http://192.168.59.103:49159/
I did not need to add any
route
on the hostHow to troubleshoot the issue on hosting application on local host browser
For this launch the container with below command, in my case it was:
In the httpd configuration:
edit the file with the port 8000 in listner and update the container ip and port under Servername.
Restart the httpd service and you are done.
Hope this helps
To find the IP address of your container, you should need NO additional installs:
This provides a wealth of info.
grep
it for the IP address.