Tuesday, December 04, 2018

How to find Docker host IP

On Mac:

$ docker run -it busybox /bin/sh

Inside the container:

/ # pwd
/
/ # ping docker.for.mac.localhost
PING docker.for.mac.localhost (192.168.65.2): 56 data bytes
64 bytes from 192.168.65.2: seq=0 ttl=37 time=6.215 ms
64 bytes from 192.168.65.2: seq=1 ttl=37 time=0.698 ms
64 bytes from 192.168.65.2: seq=2 ttl=37 time=0.423 ms
64 bytes from 192.168.65.2: seq=3 ttl=37 time=0.324 ms
64 bytes from 192.168.65.2: seq=4 ttl=37 time=0.647 ms
^C
--- docker.for.mac.localhost ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 0.324/1.661/6.215 ms

On Mac:
$ export HOST_IP=192.168.65.2
$ echo $HOST_IP
192.168.65.2
$ docker run --add-host outside:$HOST_IP --name busybox -it busybox /bin/sh
/ # cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.65.2 outside
172.17.0.4 b0d28743cbcb

Reference