background

These two days encounter a strange problem: open happy heart connect server, ready to run on their own service. To facilitate deployment, install Docker first, of course. Happy installation, write Dockerfile, write finished run! Access, meng bi, can not access, direct ping impassability. Because I found this problem suddenly, I did not doubt the problem of Docker too much. I just found that Docker still did not work after I shut it down, so Docker was excluded.

The phenomenon of

After a fault occurs, you can log in to the server using SSH, but the server cannot be pinged or accessed.

subsequent

The thief heart never died, and then applied for a server, this time learned smart, first ping, found that you can ping through, then install Docker and ping again, cool! Problem location is Docker’s pot! So what do we do?

It’s easy to be sure it’s Docker’s, but Google found a similar problem.

The original is Docker and host network segment conflict, change the network segment is good.

By default, the Docker container network uses the bridge mode. Containers usually use the virtual bridge defined in daemon.json to communicate with hosts.

The following are the methods of modifying the default Docker network segment for Linux and Mac respectively.

Change the method

Linux Change the default Docker network segment

Step 1 Delete the original configuration

sudo service docker stop
sudo ip link set dev docker0 down
sudo brctl delbr docker0
sudo iptables -t nat -F POSTROUTING
Copy the code

Step 2 Create a new bridge

Sudo BRCTL addbr docker0 sudo IP addr add 172.17.10.1/24 dev docker0 sudo IP link set dev docker0 upCopy the code

The third step is to configure the Docker files

Json {"bip":"172.17.10.1/24"} vi /etc/docker/ daemon.json-bash -4.2$cat /etc/docker/daemon.json {"bip":"172.17.10.1/24"}#Note that the value of BIP is changed to the new set of network segment
Copy the code

Mac modified

Open Preferences -> Advanced and change the 172.17.10.1/24 configuration for the Docker Subnet to avoid network segment conflicts.