Unable to access local network IP from docker container

后端 未结 4 720
生来不讨喜
生来不讨喜 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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-05 22:01

    I tried the following, and it works:

    mac-os $> ifconfig
    en0: flags=8863 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
        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
    [...]
    

提交回复
热议问题