Unable to access local network IP from docker cont

2019-03-25 19:01发布

Running macOS and docker ubuntu on it, I am unable to ping my local network's IP addresses. Below is the network configuration of my docker container. I can ping my host machine's IP address but I am unable to access other IP addresses on the local network.

root# ping 172.17.101.192
PING 172.17.101.192 (172.17.101.192) 56(84) bytes of data.
From 172.17.0.3 icmp_seq=1 Destination Host Unreachable
From 172.17.0.3 icmp_seq=2 Destination Host Unreachable

root# ifconfig         
eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:03
          inet addr:172.17.0.3  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:acff:fe11:3/64 Scope:Link

Is there any network configuration which would help me to perform this operation?

I have tried net=host but it is not helping it.

4条回答
唯我独甜
2楼-- · 2019-03-25 19:13

I was using docker for mac, the issue was docker internal network conflicting with my local network addressing. To resolve the this issue, i need to go to Preferences in the dokcer menu. In Preferences menu Daemon>Advanced Menu, i can supply other bip.

{
    "bip" : "12.12.0.1/24"
}

Click apply and restart. The next time docker will start with internal network as 12.12.0.1/24.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-03-25 19:31

I tried the following, and it works:

mac-os $> ifconfig
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether 78:31:c1:bd:4b:84 
    inet6 fe80::1425:a90d:9c00:ef53%en0 prefixlen 64 secured scopeid 0x4 
    inet 10.191.41.1 netmask 0xfffff800 broadcast 10.191.47.255
    nd6 options=201<PERFORMNUD,DAD>
    media: autoselect
    status: active

So my ip is 10.191.41.1. Then I do:

mac-os $> docker run -ti --rm ubuntu bash -c "apt-get update && apt-get install -y inetutils-ping && ping 10.191.41.1"

Which installs the "ping" command, and tries to ping my host. I get the right answers:

[...]
PING 10.191.41.1 (10.191.41.1): 56 data bytes
64 bytes from 10.191.41.1: icmp_seq=0 ttl=37 time=0.303 ms
64 bytes from 10.191.41.1: icmp_seq=1 ttl=37 time=0.536 ms
[...]
查看更多
太酷不给撩
4楼-- · 2019-03-25 19:32

I'm guessing you're using docker-machine.

You should check out docker for mac as it has some networking improvements that may make this work for you. This is what I'm using and I'm able to reach other hosts on my internal network from docker.

查看更多
不美不萌又怎样
5楼-- · 2019-03-25 19:37

I think docker internal network could be conflicting with your local network addressing.

Try to run Docker changing the default internal network to something that doesn't conflict, as 172.31.0.0/24. Add to your Docker startup options --bip 172.31.0.1/24, probably located in /etc/default/docker:

# Use DOCKER_OPTS to modify the daemon startup options.
DOCKER_OPTS="--bip 172.31.0.1/24"

UPDATE: Although this is true in Linux, Mac implementation is different, see docs here, so it depends if you're using Docker for Mac or for Linux.

Just to test, try to attach your laptop to a different network, any in the range of 192.168.0.0/16 would suffice.

查看更多
登录 后发表回答