Solve the problem that docker can't communicate with ping under Mac

  • 2021-09-20 21:53:45
  • OfStack


Discard the linux virtual machine that comes with docker for mac (although it is lightweight, it communicates with OSX in the way of socket file) and use docker-machine

Install virtualbox. After virtualbox is created, a virtual network card will be added, which can be viewed through ifconfig command. The way we realize it is to use this virtual network card.

Create the default linux virtual machine using docker-machine, command docker-machine create

Switch the docker environment using the eval $(docker-machine env) command

Look at the ip address of the created virtual machine: docker-machine ip default or direct docker-machine ip, if it is 192.168. 99.100

Execute the route command, using 192.168. 99.100 as a gateway, and route the ip segment of the docker container to this IP. If the docker container has a segment of 172.17. 0.0/16, add routing information using the command sudo route-ES50add-net 172.17. 0.0/16 192.168. 99.100.

Start an docker container, and this test uses redis: alpine mirror: docker run-d redis: alpine. View the running mirror IP. And ping test. If there is no accident, the host machine can be ping with the container at present.


eval "$(docker-machine env -u)"

It cancels the DOCKER_* variable.

For recording, this is the output docker-machine env-u:


Supplementary knowledge: Mac Docker Host mode cannot be used

Today, fastdfs is installed in docker built by Mac, and tracker and storage are started in host mode.

It turned out that the host network driver was only for Linux hosts and did not support Docker for Mac, Docker for Windows, or Docker EE for Windows Server.

There is still this restriction. Yes, I wasted a day.

Related articles: