Docker Community Forums

Share and learn in the Docker community.

How to access docker container from another machine on local network


(Albert Varaksin) #1

I have installed a docker container and it is working, but only on my local machine. I can access it through the specific container IP, but noone else can access this from another computer on the same local network. In other words how do I make my container reachable for other people?

OS: OSX 10.11.1
Docker toolbox: Docker version 1.9.1, build a34a1d5

Thanks


(Ranjandas) #2

Hi,

You should expose the ports which your service inside container is listening on to the host.

For example if you are running apache httpd inside container on port 80 and other people in the same network want to access it you should do the following.

docker run -d -p 80:80 apache

In the example we are mapping port 80 of container to host port 80. So now others on your network can access port 80 of your host to hit port 80 of container.

Regards


(Albert Varaksin) #3

Thanks for your comment, but you have misunderstood the issue. Problem is not accessing container from the host machine, but other computers on the local network. This is because docker-machine assigns an ip to the docker vm that is only visible from the host machine. My question is how can other computers on local network access my docker container.


(Ranjandas) #4

Sorry, my bad. Now for your requirement you will have to run the boot2docker vm network in bridge mode so that your VM will get an IP in your LAN subnet. After that when you expose ports using -p other people in the network can access it using the ip which you got for the boot2docker vm. In virtualbox you should modify the Adapter 2 settings as shown. Btw the bridge interface in your case may vary.

Regards


(Tryer3000) #5

for windows host, I edit this value in Virtualbox Manager.
But docker will switch back to host-only adapter.


(Rashmi22) #6

Did you fix it? if yes please let e know how.

I am on a LAN and users can ping my system’s ip but as container is running on Private ip and I want to make it available over LAN


(Vittel) #7

I have the same issue with docker for windoes. Could you provide a solution for this please?


(Fernandofr) #8

Same here, Docker for Mac, version 1.11.1-beta14 (build: 8670).


(Brucezhaor) #9

@ranjandas Could please speak a little more clearly? perhaps with some more snapshots. The Same problem in window docker toolbox. Thank you in advance!


(Martinjh99) #10

If I read the docs right all you need to do is this:

docker run --network=host …

host network should piggy back on the host computers connection rather than just machine that the container is running on.


(Arbitrage) #11

I am also facing same issue. Could you please share solution for the same


(Narenasha) #12

http://blog.oddbit.com/2014/08/11/four-ways-to-connect-a-docker/
This might help you


(Rajeevuta) #13

Hi https://forums.docker.com/u/ranjandas,

When we are trying to as you mentioned above,after restart ,it is again resetting back to defualt settings.

How to change that?


(Mdorfman) #14

Thank you! It worked for me.
I send message from Windows host -> 192.168… which is virtualbox guest hosting the docker -> docker’s app.

docker run --network=host … allows application in docker to see 192.168.56… as one of network interfaces and listen on it


(Jaredharringtongibbs) #16

Forward the windows port to the docker vm.
Open powershell as administrator and run the following commands.

cd 'C:\Program Files\Oracle\VirtualBox\'
then
./VBoxManage controlvm "default" natpf1 "rule-name,tcp,,<port>,,<port>"

If that still does not work try:

Manually adding routes to the docker containers.

Connect to the docker machine by running:

docker-machine.exe ssh default

Find it’s local ip addresses by running :

ifconfig

On the windows host run powershell as administrator.
Find the virtual box interface(s) by running:

ipconfig

Locate the windows ip address that matches subnets with the docker machine.

docker address=192.168.99.100
windows address=192.168.99.1

Add a route to the internal docker interface(s) by running

route add <subnet> MASK <mask range> <windows ip gateway>
e.g. route add 10.0.2.0 MASK 255.255.255.0 192.168.99.1
e.g. route add 172.17.0.0 MASK 255.255.0.0 192.168.99.1

Check the windows host’s route have been forwarded by running

netstat -r

Ensure connectivity by pinging the docker’s internal address(es).

ping 10.0.2.xxx"


(Demonquark) #17

This worked for me. Thanks. :smiley: