How to access docker container from another machine on local network

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

1 Like

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

1 Like

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.

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

1 Like

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

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

5 Likes

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

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

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

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.

1 Like

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

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

1 Like

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?

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

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"

1 Like

This worked for me. Thanks. :smiley:

@ranjandas ,I have created a Docker Image for WebApplication. In ubuntu machine the IP Address is changing dynamically how to access that application with url.
I can Access my Application http://localhost:5000.But I need to give the url to other people…the IPAddress is changing dynamically how i have to give?
How this application will be accessed by other people?

I found the solution recently when I was trying to solve this problem. It is firewall issue where docker network adapter vEthernet (DockerNAT) is unidentified network and set to public network category and doesn’t allow remote access to docker container. And this needs to be resolved by adding Inbound rule in windows firewall section for windows create a rule that is suitable for your need.

I tried solution from below link
https://github.com/docker/for-win/issues/367#issuecomment-277181930 but it didn’t not yield any positive result as docker was dynamically creating DockerNAT virtual switch that is set to public and unidentified network.

So work around would be adding inbound rule in firewall section if you are using windows. That solved this issue.

Hi ,
Am new to docker.am trying to bring up one setup on linux.
Where i have 2 container i.e A and B and i have one proxy server X
I am able to send msges from A to X but am not able to send or ping from X to B.
I want to know how i can achive this.
By Dockert HOSt container have eth0 and eth1 interface
Container A is using eth0 to send packets from A to X and i want to use eth1 to recieve the packet from X
Can you please help me on this?

Hi!
I am also new to docker and even I got a lot of things working perfectly, I am completely failing on doing one simple thing:
I have one server running several docker container providing different services on different ports. Using the simple bridge network, this works totally fine. Example: Unifi Controller is http://192.168.1.5:8080 and UniFi Video is http://192.168.1.5:7080.

But by installing more and more services as docker containers, I run into difficulties as multiple ports are the same on different services. In addition, I want to switch some services to a secondary IP address that is not the one that is set as exposed host in my router.

I read a lot of complex 172.x.x.x internal docker networking and linking and such, but I cannot find a document that simply explains how to do the following:

Linux machine running on 192.168.1.5, docker container on that machine running on 192.168.1.6 and another one on 192.168.1.7 over the same physical network on that linux machine.
I have NAT and firewall running on my master router, I don’t want to add another layer of NAT or routing.

Thanks for any help!