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

Detailed explanation of MySQL combined query

Using UNION Most SQL queries consist of a single ...

Using css-loader to implement css module in vue-cli

【Foreword】 Both Vue and React's CSS modular s...

Introduction to HTML link anchor tags and their role in SEO

The <a> tag is mainly used to define links ...

W3C Tutorial (7): W3C XSL Activities

A style sheet describes how a document should be ...

Introduction to TypeScript basic types

Table of contents 1. Basic types 2. Object Type 2...

MySQL character types are case sensitive

By default, MySQL character types are not case-se...

Solution to forgetting MySQL root password in MACOS

MySQL is a relational database management system ...

Linux kernel device driver kernel debugging technical notes collation

/****************** * Kernel debugging technology...

Summary of MySQL log related knowledge

Table of contents SQL execution order bin log Wha...

Docker Gitlab+Jenkins+Harbor builds a persistent platform operation

CI/CD Overview CI workflow design Git code versio...

MySQL 5.7.17 installation and use graphic tutorial

MySQL is a relational database management system ...

How to deploy DoNetCore to Alibaba Cloud with Nginx

Basic environment configuration Please purchase t...

How to use JSX to implement Carousel components (front-end componentization)

Before we use JSX to build a component system, le...

Explanation of factors affecting database performance in MySQL

A story about database performance During the int...