In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the method of adding a custom bridge to Docker, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
The Docker service process generates a bridge named docker0 when it starts, and the container is mounted to it by default, but we can choose which bridge to use by adding the docker startup parameter-b Birdge or changing the docker configuration file.
Operating system: centos7
Delete docker0 Brid
Service docker stop / / close the docker service ip link set dev docker0 down / / close the docker0 bridge ip link del dev docker0 / / delete the docker0 bridge
Customize bridge settings (/ etc/sysconfig/network-scripts/ifcfg-br0 file)
DEVICE= "br0" ONBOOT= "yes" TYPE= "Bridge" BOOTPROTO= "static" IPADDR= "10.10.10.20" NETMASK= "255.255.255.0" GATEWAY= "10.10.10.20" DEFROUTE= "yes" NM_CONTROLLED= "no"
Restart network services
Service network restart
View Brid
[black@test opt] $brctl show bridge name bridge id STP enabled interfaces br0 8000.32e7297502be no virbr0 8000.000000000000 yes
Next, we need to restart docker, and we can use the following two ways when starting the docker service process:
The first: the-b parameter specifies the bridge
[root@test opt] # docker-d-b br0 INFO [0000] Listening for HTTP on unix (/ var/run/docker.sock) INFO [0000] [graphdriver] using prior storage driver "devicemapper" WARN [0000] Running modprobe bridge nf_nat failed with message:, error: exit status 1 INFO [0000] Loading containers: start. . INFO [0000] Loading containers: done. INFO [0000] Daemon has completed initialization INFO [0000] Docker daemon commit=786b29d execdriver=native-0.2 graphdriver=devicemapper version=1.7.1
I don't know why starting the docker service process in this way will block the current terminal, so I have to reopen a terminal and run a container.
[root@test shell] # docker run-ti-- rm centos:latest [root@3c6874559411 /] # ifconfig eth0 Link encap:Ethernet HWaddr 02:42:0A:0A:0A:01 inet addr:10.10.10.1 Bcast:0.0.0.0 Mask:255.255.255.0 inet6 addr: fe80::42:aff:fe0a:a01/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5 errors:0 dropped:0 overruns: 0 frame:0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:418 (418.0 b) TX bytes:508 (508.0 b)
The container successfully used the br0 bridge.
Second: modify / etc/sysconfig/docker file
I had a problem with this operation. I modified the / etc/sysconfig/docker file.
[root@test opt] # vi / etc/sysconfig/docker # / etc/sysconfig/docker # # Other arguments to pass to the docker daemon process # These will be parsed by the sysv initscript and appended # to the arguments list passed to docker-d other_args= "- b br0"
Then use service docker start to start the docker service, but other_args does not take effect, under centos7 servicer docker start will still use the systemctl start docker.service command to run, so I open / usr/lib/systemd/system/docker.service to see
[root@test opt] # vi / lib/systemd/system/docker.service [Unit] Description=Docker Application Container Engine Documentation= https://docs.docker.com After=network.target docker.socket Requires=docker.socket [Service] ExecStart=/usr/bin/docker-d-H fd:// MountFlags=slave LimitNOFILE=1048576 LimitNPROC=1048576 LimitCORE=infinity [Install] WantedBy=multi-user.target
Finding that the ExecStart item has no running parameters, change the ExecStart to / usr/bin/docker-d-b br0-H fd://, to run the docker service and start a container to discover that the br0 bridge can be used successfully.
See a better way to change docker.service to the following on the Internet
[black@test ~] $vi / usr/lib/systemd/system/docker.service [Unit] Description=Docker Application Container Engine Documentation= https://docs.docker.com After=network.target docker.socket Requires=docker.socket [Service] EnvironmentFile=-/etc/sysconfig/docker ExecStart=/usr/bin/docker-d $other_args-H fd:// MountFlags=slave LimitNOFILE=1048576 LimitNPROC=1048576 LimitCORE=infinity [Install] WantedBy=multi-user.target
At this point, the parameters added to the other_args are valid.
Thank you for reading this article carefully. I hope the article "how to add a custom bridge to Docker" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.