A fair number of commenters asked a related question in a previous post. This post serves as quick information on troubleshooting connecting to containers from Docker Desktop for macOS, from: https://biancatamayo.me/blog/2017/11/03/docker-add-host-ip/#comment-4412585659
For people having issues accessing containers from their macOS here's some info:
Docker networking works differently for macOS than it does on Linux (it uses HyperKit).
If you're using Docker Desktop for Mac, you won't be able to ping your containers by IP. See: https://docs.docker.com/docker-for-mac/networking/
Issue: I cannot ping my containers
Docker Desktop for Mac can’t route traffic to containers.
BUT you should be able to connect using another port if you publish the ports correctly, using
localhost, not the IP address.
If I run the following command to run
nginx in a container and expose port
80 inside the container, and map to port 80 on the host:
docker run -d -p 80:80 --name webserver nginx
It will have the following effect in macOS. It works as expected with curl using localhost.
$ curl -I localhost:80 HTTP/1.1 200 OK Server: nginx/1.15.10
But if I try to use the IP address in macOS:
# Getting the IP address of the webserver container $ docker inspect webserver | jq '. | .NetworkSettings.Networks.bridge.IPAddress'
which returned in this case "
Now using that returned IP in macOS (i.e. fails ping, and fails curl):
$ ping 172.17.0.3 PING 172.17.0.3 (172.17.0.3): 56 data bytes Request timeout for icmp_seq 0 Request timeout for icmp_seq 1 ^C --- 172.17.0.3 ping statistics --- 3 packets transmitted, 0 packets received, 100.0% packet loss
The following times out:
$ curl -I 172.17.0.3:80 ...
This link contains a lot more troubleshooting on macOS + Docker networking: https://docs.docker.com/docker-for-mac/networking/