Accessing Docker Containers From The Outside World?

10,734 views
Skip to first unread message

Ray Jender

unread,
Jul 6, 2014, 12:43:10 PM7/6/14
to docke...@googlegroups.com

So I played with LXC a bit and now I am looking at Docker.

How do you set up the containers to be accessed from the outside world? (eg. I have a website built in a container.)
Right now the docker containers are being assigned IP's on the 172.17.0.X subnet. LXC has a similar issue for
me as it assigns IP's in the 10.0.x.x range.

I really don't want to do port forwarding on the host. I want to be able to access the website from my LAN.


Thanks,

Ray

nicolas de loof

unread,
Jul 6, 2014, 1:32:48 PM7/6/14
to Ray Jender, docke...@googlegroups.com
Not sure I understand your question. If you run container with -p 80:8080, you'll be able to access in-container web server running on port 8080 from outside world, querying port 80 on docker host.


--
You received this message because you are subscribed to the Google Groups "docker-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to docker-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ray Jender

unread,
Jul 6, 2014, 6:02:34 PM7/6/14
to docke...@googlegroups.com, rayje...@gmail.com
So, how to set that up.  Container IP is 172.17.0.3.  You cannot route to that IP from the outside.

here is my network:

Host eth0 = 192.168.1.148
  |
Host docker0 = 172.17.42.1
  |
Host vetha467 = no ipv4 assigned
  |
  |_ root@6b6823f5bd7a eth0 = 172.17.0.3

From 192.168.1.148 I can browse to 172.17.0.3 just fine.

So, how would this work if it were in the internet with a
the host IP of Cox cable for instance?


Thanks,

Ray

Sven Dowideit

unread,
Jul 6, 2014, 6:41:07 PM7/6/14
to docke...@googlegroups.com
Ray,

You don't need to set that up - Docker does it for you.

When you run the container:

docker run -d -p 8080:80 webserver-image

Docker will set up the port forwarding from your host's port 8080 to the container's port 80 using iptables.

What you're showing as 'your' network is the Docker daemon's network - and it deals with wiring things up.

you might find http://docs.docker.com/articles/networking/ useful

Cheers
Sven

Budh Ram

unread,
Jul 14, 2015, 3:12:27 AM7/14/15
to docke...@googlegroups.com
Hi, 
I had similar requirement as Ray has.

I my machine I am setup 3 containers for three different applications.
Now, I want to access these applications with their IPs. Since these IPs are private and created by docker daemon.

Is it possible to give these containers the IP range of eth0 ?

nicolas de loof

unread,
Jul 14, 2015, 3:17:06 AM7/14/15
to Budh Ram, docker-dev
when you use docker -p option a port is opened on host (so can be accessed from the outside world) and routed inside container (can be on a distinct port)
so if you run `docker run -p 8080:8080 myApp` you will have your app exposed to the internet on host port 8080 with host IP
and you also can select a distinct port and do some NAT, for sample to use port 80 without a reverse proxy

Dreamcat4

unread,
Jul 14, 2015, 5:57:45 AM7/14/15
to nicolas de loof, Budh Ram, docker-dev
If you want the equivalient of vmware's 'bridged networking mode' (NIC promiscuous mode). Then use pipework.


Reply all
Reply to author
Forward
0 new messages