preface

Recently, WHEN I logged in to the remote server of the company by SSH, I suddenly failed to log in. After investigation, it is because the network segment of a Docker container conflicts with the network segment of the company, so I failed to log in.

How to solve

The default network segment of docker is 172.17, which conflicts with the network segment of the company. Therefore, the solution is actually quite simple, either change the network segment of the company or change the docker network segment. A normal person would choose to change the docker network segment

The solution

Solution 1: Do not change the Docker network segment and create a Docker subnet segment that does not conflict with the corporate network segment

docker network create --driver=bridge --subnet=192.161.0.0/16 monitor_net
Copy the code

Specified when the container is run

docker run -it --name< container name > ---networkMonitor_net < The image nameCopy the code

Docker-compose is also specified by networks as follows

version: '3'
networks:
   monitor:
   # Use an existing network
     external:
       name: monitor_net  

services:
    prometheus:
        image: prom/prometheus
        container_name: prometheus
        hostname: prometheus
        privileged: true
        restart: always
        volumes:
            - /usr/local/src/config/prometheus.yml:/etc/prometheus/prometheus.yml
            - /usr/local/src/config/node_down.yml:/etc/prometheus/node_down.yml
        ports:
            - "9091:9090"
        networks:
            - monitor
        links:
            - alertmanager
            - node-exporter
Copy the code

Solution 2: Modify the default docker network segment

1. Stop Docker

systemctl stop docker
Copy the code

2. Delete the original network bridge

ip link del docker0 down
Copy the code

3, vim /etc/docker-daemon. json, add the following content

"bip":"192.161.20.1/24"
Copy the code

If no daemon.json file exists, create one

The file content is as follows

{
  "registry-mirrors": ["https://zq2cvqfe.mirror.aliyuncs.com"]."insecure-registries": ["192.168.1.30:5002"]."bip":"192.161.20.1/24"
}

Copy the code

4. Restart the Docker service

systemctl restart docker
Copy the code

5. Run ifconfig to check whether the Docker network segment has changed

conclusion

When installing Docker, remember to modify the default docker, so as not to conflict with the company’s network segment