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

MySQL SHOW PROCESSLIST assists in the entire process of troubleshooting

1. SHOW PROCESSLIST command SHOW PROCESSLIST show...

Detailed explanation of CSS margin collapsing

Previous This is a classic old question. Since a ...

Sharing of SVN service backup operation steps

SVN service backup steps 1. Prepare the source se...

Practice using Golang to play with Docker API

Table of contents Installing the SDK Managing loc...

Detailed explanation of JS browser storage

Table of contents introduction Cookie What are Co...

An example of implementing a simple infinite loop scrolling animation in Vue

This article mainly introduces an example of Vue ...

Implementation of nginx flow control and access control

nginx traffic control Rate-limiting is a very use...

Installation tutorial of MySQL 5.7 green version under windows2008 64-bit system

Preface This article introduces the installation ...

Summary of Kubernetes's application areas

Kubernetes is the leader in the container orchest...

jQuery uses the canvas tag to draw the verification code

The <canvas> element is designed for client...

Explanation of the problem that JavaScript strict mode does not support octal

Regarding the issue that JavaScript strict mode d...

How to install docker on Linux system and log in to docker container through ssh

Note: I use Centos to install docker Step 1: Inst...

VMWare Linux MySQL 5.7.13 installation and configuration tutorial

This article shares with you the tutorial of inst...