How to access Docker container web server from host

I am running under boot2docker 1.3.1.

I have a Docker container running a web server via uwsgi --http :8080 .

If I join the container, I can browse the website using lynx http://127.0.0.1:8080 , so I know that the server is working.

I launched the container using

 $ docker run -itP --expose 8080 uwsgi_app:0.2 

It has the following data:

 $ 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 this website from my host by going to http://172.17.0.107:49159 .

This does not work. I just see a "connection ..." in Chrome without getting anywhere.

What am I doing wrong?

+44
docker boot2docker
Nov 28 '14 at 15:31
source share
8 answers

Ok, silly to me, I found the answer in the docs for boot2docker https://docs.docker.com/installation/mac/#container-port-redirection

I needed to use the boot2docker vm ip address, not the container ip, i.e.

 $ boot2docker ip 192.168.59.103 

and I can view my site from the host at http://192.168.59.103:49159/

I did not need to add any route to the host

+33
Nov 28 '14 at 15:51
source share

Anentropic answer extension: boot2docker is an old application for Mac and Windows, docker-machine is new.

First, list your cars:

 $ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM default * virtualbox Running tcp://192.168.99.100:2376 

Then select one of the machines (by default it is called default ) and:

 $ docker-machine ip default 192.168.99.100 
+89
Sep 05 '15 at 23:19
source share

To find the IP address of your container, you need NO additional settings :

 docker inspect <container> 

It gives a ton of information. grep for the IP address.

+7
Aug 10 '16 at 16:06
source share

You can use the boot2docker -L port mapping option, as described here .

So in your case it will be

 boot2docker ssh -L 0.0.0.0:8080:localhost:8080 

and then

 docker run -it -p 8080:8080 uwsgi_app:0.2 

Thus, you do not need to use the boot2docker IP address: you can use localhost or your own IP address (and you can access your docker container from the outside).

+4
Dec 01 '14 at 16:02
source share

Had the same problem and in my case I used an instance of AWS EC2. I tried with an IP container that did not work. Then I used the actual public IP address of the AWS host as the IP address that worked.

+1
06 Sep '16 at 13:21
source share

[EDIT: The original version ignored the -P question]

If you want to get into containers, do not β€œpublish” the port (which changes its number) there is a good pass-through here .

The key to this line is:

 sudo route -n add 172.17.0.0/16 172.16.0.11 

which tells Mac how to redirect to a private network inside a virtual virtual machine that includes Docker containers.

0
Nov 28 '14 at 15:38
source share

Boot2docker is deprecated, but you may have a problem with Docker for Windows or Mac, although the same container works on Linux. One of the symptoms is that an attempt to access the page on the server inside the container gives the error "do not send any data" and not "cannot connect."

If this is the case, this is probably due to the fact that on Win / Mac the container host has its own IP , it is not localhost, like on linux, try running Django on IP 0.0.0.0, that is, accept connections from all IP addresses, eg:

 python manage.py runserver 0.0.0.0:8000 

Alternatively, if you need to make sure that the server only responds to local requests (for example, from your local proxy, such as nginx, apache or gunicorn), you can use the host IP returned by hostname -i .

And make sure you use the -p port forwarding option correctly in the docker run .

Assuming all is well, you should have access to your server at http: // localhost in a browser running on the host machine.

0
Apr 10 '17 at 22:17
source share

How to fix a problem when placing an application in a local host browser

For this run the container with the command below, in my case it was:

 [root@centoslab3 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1b81d8a0e3e1 centos:baseweb "/bin/bash" 8 minutes ago Exited (0) 24 seconds ago webtest [root@centoslab3 ~]# docker run --name=atul -v /root/dockertest:/var/www/html -i -t -p 5000:8000 centos:baseweb /bin/bash 

In the httpd configuration:

 [root@adb28b08c9ed /]# cd /etc/httpd/conf [root@adb28b08c9ed conf]# ll total 52 -rw-r--r--. 1 root root 34419 Sep 19 15:16 httpd.conf 

edit the file with port 8000 in the list and update the ip and container port under the name Server.

Restart the httpd service and you're done.

Hope this helps

0
Dec 15 '17 at 11:13
source share



All Articles