Solve the problem that Docker cannot ping the host machine under Mac

Solve the problem that Docker cannot ping the host machine under Mac

Solution

Abandon the Linux virtual machine that comes with Docker for Mac (although it is lightweight, it communicates with OSX using socket files) and use docker-machine

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

Use docker-machine to create a default Linux virtual machine, command docker-machine create

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

Check the IP address of the created virtual machine: docker-machine ip default or directly docker-machine ip, if it is 192.168.99.100

Execute the route command, use 192.168.99.100 as the gateway, and route the IP segment of the docker container to this IP. If the network segment of the Docker container is 172.17.0.0/16, use the sudo route -n add -net 172.17.0.0/16 192.168.99.100 command to add routing information.

Start a Docker container. This test uses the redis:alpine image: docker run -d redis:alpine. Check the running mirror IP. And ping test. If nothing unexpected happens, the host machine can now ping the container.

Replenish:

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

It will unset the DOCKER_* variables.

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

unset DOCKER_TLS_VERIFY
unset DOCKER_HOST
unset DOCKER_CERT_PATH
unset DOCKER_MACHINE_NAME

Additional knowledge: Mac Docker Host mode cannot be used

Today I installed fastdfs in docker on Mac, and started tracker and storage in host mode, but it didn't work.

Turns out the host network driver only works with Linux hosts, and is not supported on Docker for Mac, Docker for Windows, or Docker EE for Windows Server.

There is actually this limitation. Damn, a day wasted.

The above article on solving the problem that docker cannot ping the host machine under Mac is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Solution to the Docker container being unable to access the host port
  • How to use Docker container to access host network
  • The docker container directly runs to obtain the public IP operation through ping

<<:  A brief discussion on the understanding of TypeScript index signatures

>>:  Write a formal blog using XHTML CSS

Recommend

Share the 15 best HTML/CSS design and development frameworks

Professional web design is complex and time-consu...

MySQL 5.7.21 installation and configuration method graphic tutorial (window)

Install mysql5.7.21 in the window environment. Th...

Vue implements simple comment function

This article shares the specific code of Vue to i...

JavaScript+html to implement front-end page sliding verification (2)

This article example shares the specific code of ...

js implements axios limit request queue

Table of contents The background is: What will ha...

Implementation of nested jump of vue routing view router-view

Table of contents 1. Modify the app.vue page 2. C...

Detailed explanation of Tomcat configuration and optimization solutions

Service.xml The Server.xml configuration file is ...

Modify the default scroll bar style in the front-end project (summary)

I have written many projects that require changin...

XHTML 2.0 New Features Preview

<br />Before browsers can handle the next ge...