Unable to access local network IP from docker container

后端 未结 4 721
生来不讨喜
生来不讨喜 2021-02-05 21:35

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 machin

相关标签:
4条回答
  • 2021-02-05 21:52

    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.

    0 讨论(0)
  • 2021-02-05 22:01

    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
    [...]
    
    0 讨论(0)
  • 2021-02-05 22:04

    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.

    0 讨论(0)
  • 2021-02-05 22:05

    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.

    0 讨论(0)
提交回复
热议问题