Docker Community Forums

Share and learn in the Docker community.

Accessing local network from Docker container

docker

(Jansu) #1

Hello!

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 192.168.254.0/24, for example:

  • 192.168.254.49
  • 192.168.254.50
  • 192.168.254.51

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 192.168.254.0/24 from Docker container (currently in default bridged network 172.17.0.0/24)?

Thanks in advance!


(David Maze) #2

You shouldn’t have to do anything. What’s the host’s IP address? (Is it on the 192.168.254.0/24 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 192.168.254.2, and you did something like

docker run --rm busybox wget -O- http://192.168.254.49/

I’d expect it to work.)


(Jansu) #3

Host is Debian 9 and in the same network with IP 192.168.254.100. 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 192.168.254.49 and other computers.

I tried with …

docker run --rm busybox wget -O- http://192.168.254.49/

… but I get …

wget: can't connect to remote host (192.168.254.49): 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 172.17.0.0/16 -j MASQUERADE

Thanks for help anyway!