Access IP address of a server running in lan network from inside docker

Viewed 17

I have a docker container running, but I am not able to access an IP address of a server running on same network where my host machine is running.

For example run a docker container with following command

docker run -it --entrypoint bash debian:stable-slim

And enter following command for using pingutils

apt-get update && apt-get -u iputils-ping

Now if I ping the server running on my local network, I don't get response. enter image description here

Similarly I am not able to access any ip address that are running on my lan network from inside docker container.

My docker is configured to use following ip addresses enter image description here

Whereas docker network's inspection output is as followed

"NetworkSettings": {
    "Bridge": "",
    "SandboxID": "0a86e625c875ba2beb828664c5bc917f977056f5b1fc63612db1086ad7ae7e58",
    "HairpinMode": false,
    "LinkLocalIPv6Address": "",
    "LinkLocalIPv6PrefixLen": 0,
    "Ports": {},
    "SandboxKey": "/var/run/docker/netns/0a86e625c875",
    "SecondaryIPAddresses": null,
    "SecondaryIPv6Addresses": null,
    "EndpointID": "b1646887e464da02a1ce21bfb550f44094704b8db5e8ce9729cfa9f48d064c2e",
    "Gateway": "192.168.0.1",
    "GlobalIPv6Address": "",
    "GlobalIPv6PrefixLen": 0,
    "IPAddress": "192.168.0.2",
    "IPPrefixLen": 24,
    "IPv6Gateway": "",
    "MacAddress": "02:42:c0:a8:00:02",
    "Networks": {
        "bridge": {
            "IPAMConfig": null,
            "Links": null,
            "Aliases": null,
            "NetworkID": "cbfeb95807852ce2d1e56025b6115ddef322971d120f0f9ff29ba1f234a3ff1f",
            "EndpointID": "b1646887e464da02a1ce21bfb550f44094704b8db5e8ce9729cfa9f48d064c2e",
            "Gateway": "192.168.0.1",
            "IPAddress": "192.168.0.2",
            "IPPrefixLen": 24,
            "IPv6Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "MacAddress": "02:42:c0:a8:00:02",
            "DriverOpts": null
        }
    }
}
1 Answers

The problem is docker is using the same ip pool to assign to containers as my lan dhcp. I need to update docker configuration to use different IP pool for bridge network.

That could be done by adding following entry in Docker Engine settings.

"default-address-pools": [
  {
    "base": "172.30.0.0/16",
    "size": 24
  }
],

This settings are available at Preference > Docker Engine enter image description here

Related