How to modify the default network segment of Docker0 bridge in Docker

How to modify the default network segment of Docker0 bridge in Docker

1. Background

When the Docker service is started, a docker0 bridge is created by default (with a docker0 internal interface on it), which connects other physical or virtual network cards at the kernel layer, putting all containers and the local host on the same physical network.

By default, Docker specifies the IP address and subnet mask of the docker0 interface, allowing the host and container to communicate with each other through the bridge. It also gives the MTU (the maximum transmission unit allowed to be received by the interface), which is usually 1500 Bytes, or the default value supported by the host network routing. These values ​​can be configured when the service is started.

2. Environment

[root@iZ2ze278r1bks3c1m6jdznZ ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@iZ2ze278r1bks3c1m6jdznZ ~]# uname -r
3.10.0-514.26.2.el7.x86_64
[root@iZ2ze278r1bks3c1m6jdznZ ~]# docker version
Client:
 Version: 1.13.1
 API version: 1.26
 Package version: docker-1.13.1-75.git8633870.el7.centos.x86_64
 Go version: go1.9.4
 Git commit: 8633870/1.13.1
 Built: Fri Sep 28 19:45:08 2018
 OS/Arch: linux/amd64

Server:
 Version: 1.13.1
 API version: 1.26 (minimum version 1.12)
 Package version: docker-1.13.1-75.git8633870.el7.centos.x86_64
 Go version: go1.9.4
 Git commit: 8633870/1.13.1
 Built: Fri Sep 28 19:45:08 2018
 OS/Arch: linux/amd64
 Experimental: false

3. Modify the default docker0 bridge

[root@iZ2ze278r1bks3c1m6jdznZ ~]# ifconfig docker0
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    inet 172.17.0.1 netmask 255.255.255.0 broadcast 0.0.0.0
    ether 02:42:20:c4:fa:7a txqueuelen 0 (Ethernet)
    RX packets 63 bytes 4592 (4.4 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 44 bytes 4206 (4.1 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

We can see that the default network segment of docker0 is 172.xx.xx.xx

Modify the file /etc/docker/daemon.json and add the content "bip": "ip/netmask" [Do not use the same network segment as the host]

[root@iZ2ze278r1bks3c1m6jdznZ ~]# cat /etc/docker/daemon.json
{
 "bip":"192.168.100.1/24"
}

4. Restart the server

[root@iZ2ze278r1bks3c1m6jdznZ ~]# systemctl restart docker

5. Check the network segment of docker0

[root@iZ2ze278r1bks3c1m6jdznZ ~]# ifconfig docker0
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    inet 192.168.100.1 netmask 255.255.255.0 broadcast 0.0.0.0
    ether 02:42:20:c4:fa:7a txqueuelen 0 (Ethernet)
    RX packets 63 bytes 4592 (4.4 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 44 bytes 4206 (4.1 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

OK, here we have successfully modified the docker0 bridge. In the next article, I will explain how to access between containers and between containers and between containers and hosts.

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:
  • A troubleshooting experience of centos Docker bridge mode unable to access the host Redis service
  • Detailed explanation of modifying the default bridge docker0 started by docker to a custom bridge
  • How to add a custom bridge in Docker
  • Detailed explanation of how to modify the default Docker bridge address
  • How to use OpenvSwitch bridge in Docker
  • Docker uses a custom bridge
  • Docker custom bridge docker0 and docker's opening, closing, and restarting command operations

<<:  Swiper.js plugin makes it super easy to implement carousel images

>>:  MySQL 5.7.18 free installation version window configuration method

Recommend

Summary of three methods of lazy loading lazyLoad using native JS

Table of contents Preface Method 1: High contrast...

Detailed explanation of props and context parameters of SetUp function in Vue3

1. The first parameter props of the setUp functio...

Several common methods of sending requests using axios in React

Table of contents Install and introduce axios dep...

Node.js file copying, folder creation and other related operations

NodeJS copies the files: Generally, the copy oper...

Solve the problem of Nginx returning 404 after configuring proxy_pass

Table of contents 1. Troubleshooting and locating...

Mini Program to implement Token generation and verification

Table of contents process Demo Mini Program Backe...

Vue implements the method of displaying percentage of echart pie chart legend

This article mainly introduces the pie chart data...

Div picture marquee seamless connection implementation code

Copy code The code is as follows: <html> &l...

FlashFXP ftp client software registration cracking method

The download address of FlashFXP is: https://www....

Detailed steps to install JDK and Tomcat in Linux environment

Table of contents 1. Install JDK Manual Installat...

The perfect solution for highlighting keywords in HTML

I recently encountered a feature while working on...

MySQL 8.0 New Features - Introduction to Check Constraints

Table of contents Preface Check Constraints Creat...

About the layout method of content overflow in table

What is content overflow? In fact, when there is ...

How to restore docker container data

The project test environment database data is los...