Analysis of the implementation method of modifying the default network segment of Docker

Analysis of the implementation method of modifying the default network segment of Docker

background

All of the company's servers are purchased Alibaba Cloud ECS hosts. The default intranet segment is 172.16.0.0/12, and the services on the test server are basically deployed using Docker.
The Docker installed by my previous colleague on this machine is all default configuration, with the network segment of 172.17.0.0/24. In actual use, there will be a need to access the host machine through 172.17.0.1, which will conflict with other host machine IPs, so the default network segment of the container needs to be modified.

Workaround

1. Stop the Docker service on the host

sudo systemctl stop docker

2. Modify the container configuration file /etc/docker/daemon.json

sudo cat /etc/docker/daemon.json
{
  "registry-mirrors": ["https://gbs4gco0.mirror.aliyuncs.com"],
  "bip": "10.50.0.1/16",
}

As described in the above code, the bip field in the configuration file can set the docker network segment of the host machine and configure it to the private network address (192.168.0.0/10.0.0.0/172.0.0.0)

3. Start the Docker service

sudo systemctl daemon-reload
sudo systemctl start docker

4. Verify the docker-0 bridge address

sudo ifconfig
...
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    inet 10.50.0.1 netmask 255.255.0.0 broadcast 10.50.255.255
    inet6 fe80::42:46ff:fe18:add5 prefixlen 64 scopeid 0x20<link>
    ether 02:42:46:18:ad:d5 txqueuelen 0 (Ethernet)
    RX packets 14697564 bytes 5943503139 (5.5 GiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 15379709 bytes 6846099156 (6.3 GiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
...

At this point, the default network segment of Docker has been modified. You can check whether the IP of the previous container has been modified.

sudo docker container inspect alipne --format="{{.NetworkSettings.IPAdress}}"
10.50.0.2

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Correct modification steps for Docker's default network segment
  • How to modify the default network segment of Docker0 bridge in Docker
  • Detailed explanation of Docker container cross-host multi-network segment communication solution
  • Docker realizes the connection with the same IP network segment
  • Docker specifies an IP address that is in the same network segment as the host.
  • How does Docker allocate host network segment IP?
  • Docker container specifies a fixed IP/static IP address in a custom network segment

<<:  Detailed explanation of vue3 cache page keep-alive and unified routing processing

>>:  Getting Started: A brief introduction to HTML's basic tags and attributes

Recommend

Detailed explanation of how to view MySQL memory usage

Preface This article mainly introduces the releva...

Introduction to JavaScript built-in objects

Table of contents 1. Built-in objects 2. Math Obj...

Query process and optimization method of (JOIN/ORDER BY) statement in MySQL

The EXPLAIN statement is introduced in MySQL quer...

Screen command and usage in Linux

Screen Introduction Screen is a free software dev...

Basic usage of find_in_set function in mysql

Preface This is a new function I came across rece...

Detailed explanation on how to install MySQL database on Alibaba Cloud Server

Preface Since I needed to install Zookeeper durin...

ffmpeg Chinese parameter description and usage examples

1. When ffmpeg pushes video files, the encoding f...

How to execute PHP scheduled tasks in CentOS7

Preface This article mainly introduces the releva...

CSS imitates Apple's smooth switch button effect

Table of contents 1. Code analysis 2. Source code...

Reasons and solutions for prompting to save action after uploading files in form

The json data must be returned in html format That...

Appreciation of the low-key and elegant web design in black, white and gray

Among classic color combinations, probably no one...

WeChat applet implements simple calculator function

WeChat applet: Simple calculator, for your refere...