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

How to view and set the mysql time zone

1. Check the database time zone show variables li...

How to install Zookeeper service on Linux system

1. Create the /usr/local/services/zookeeper folde...

How to view and close background running programs in Linux

1. Run the .sh file You can run it directly using...

Linux editing start, stop and restart springboot jar package script example

Preface In the springboot configuration file, the...

iFrame is a great way to use it as a popup layer to cover the background

I have been working on a project recently - Budou ...

js drag and drop table to realize content calculation

This article example shares the specific code of ...

Use CSS to implement special logos or graphics

1. Introduction Since pictures take up a lot of s...

Linux sudo vulnerability could lead to unauthorized privileged access

Exploiting a newly discovered sudo vulnerability ...

Detailed explanation of two ways to dynamically change CSS styles in react

The first method: dynamically add a class to show...

Practical operation of using any font in a web page with demonstration

I have done some research on "embedding non-...

Solve the problem that Navicat cannot connect to MySQL on the Linux server

At the beginning, I felt sad. The screenshots are...

Analyzing the four transaction isolation levels in MySQL through examples

Preface In database operations, in order to effec...

MySQL compression usage scenarios and solutions

Introduction Describes the use cases and solution...

CSS to achieve particle dynamic button effect

Original link https://github.com/XboxYan/no… A bu...

Introduction to document.activeELement focus element in JavaScript

Table of contents 1. The default focus is on the ...