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

VMware vSAN Getting Started Summary

1. Background 1. Briefly introduce the shared sto...

Element Timeline implementation

Table of contents Components - Timeline Custom no...

Detailed explanation of how to use the vue verification code component

This article example shares the specific implemen...

How to use provide to implement state management in Vue3

Table of contents Preface How to implement Vuex f...

Vue implements mobile phone verification code login

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

onfocus="this.blur()" is hated by blind webmasters

When talking about the screen reading software op...

MySQL 8.0.11 installation tutorial with pictures and text

There are many tutorials on the Internet, and the...

Experience of redesigning the homepage of TOM.COM

<br />Without any warning, I saw news on cnB...

Example of ellipsis when CSS multi-line text overflows

Ellipses appear when multi-line text overflows Th...

A brief analysis of SQL examples for finding uncommitted transactions in MySQL

A long time ago, I summarized a blog post titled ...

How to configure Nginx load balancing

Table of contents Nginx load balancing configurat...

A brief discussion on JavaScript throttling and anti-shake

Table of contents Throttling and anti-shake conce...

Docker connects to the host Mysql operation

Today, the company project needs to configure doc...