Docker Community Forums

Share and learn in the Docker community.

Accessing local network from Docker container


(Jansu) #1


I’m setting up nginx:alpineas reverse proxy and would like to expose some locally available websites to the outer world. Those sites are hosted on different computers in local network, for example:


Because I wouldn’t like transfer all configurations and files from those computers to my main machine where I’m setting up nginx Docker container, I decided to create proxy. However the problem here is that when I setup nginx with proxy config, before mentioned IPs are not accessible from container (logs are showing that IPs are not accessable & ping is not responding either). I was looking how to do that with bridges and Docker networks, but couldn’t figure it out yet.

Basically the question is - what do I have to do to access my local network from Docker container (currently in default bridged network

Thanks in advance!

(David Maze) #2

You shouldn’t have to do anything. What’s the host’s IP address? (Is it on the network?) Have you tried setting up anything special with Docker, or are you using the totally default network setup? Do you need any special routing to reach that network? Any funky firewalling or routing setups?

(In the setup you describe, if the host is say, and you did something like

docker run --rm busybox wget -O-

I’d expect it to work.)

(Jansu) #3

Host is Debian 9 and in the same network with IP There is no any special configuration, I installed Docker as written in documentation (also didn’t add any volume/network/…) . Same for router - host can normally access and other computers.

I tried with …

docker run --rm busybox wget -O-

… but I get …

wget: can't connect to remote host ( Connection timed out

… after some time.

I’ve tried the same with some other images and the problem persists. However on the other machine with Windows 10 the local network is normally accessible from any container. Will try to establish Docker on other distribution and check if there is something wrong with my current installation.

(Jansu) #4

Figured out what was causing this problem - I forgot that I added service file for Docker and disabled its managing of iptables. In that case this thread explains what’s needed to establish communication between host/LAN and container. For my current needs I used this command:

iptables -t nat -A POSTROUTING ! -o docker0 -s -j MASQUERADE

Thanks for help anyway!