Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use bridging mode to build docker network

Shulou Source: shulou.com Published: 2022-06-01 01:14:36 10月05日 Update

Editor to share with you how to use bridging mode to build docker network, I hope you will learn something after reading this article, let's discuss it together!

# Host environment ubuntu server 14.04, virtual machine

# eth2:192.168.56.101

# eth3: 192.168.58.101

# 192.168.56.0Universe 24 Management Network

# 192.168.58.0 ram 24 data network, the network used by the container

# switch to the root user and execute the following command

1. Configure Linux Bridge

Brctl addbr br100

Ip addr add 192.168.58.110 dev br100 # set an IP to the bridge so that the host can access the container directly

Ip link set dev br100 up

2. Configure the Docker daemon

Echo 'DOCKER_OPTS= "- b=br100" > / etc/default/docker

Sudo service docker start

3. Start the container, set the network mode to none, and configure the container network.

Sudo docker run-it-- net=none ubuntu:14.04 / bin/bash

4. View the container process id

Docker inspect-f'{{.State.Pid}} 'CONTAINER_ID

Pid=xxx

5. Create a directory for namespaces

Mkdir-p / var/run/netns

Ln-s / proc/$pid/ns/net / var/run/netns/$pid

6. Create a veth device, assign it to the container, and bind it to the bridge

Ip link add vetha type veth peer name vethb

Brctl addif br100 vethb

Ip link set vethb up

Ip link set vetha netns $pid

Ip netns exec $pid ip link set dev vetha name eth0

Ip netns exec $pid ip link set eth0 up

Ip netns exec $pid ip addr add 192.168.58.121 Plus 24 dev eth0

Ip netns exec $pid ip route add default via 192.168.58.110

7. Bind eth3 to the bridge

Brctl addif br100 eth3

Ip addr del 192.168.58.101 ip addr del 24 dev eth3 # Delete IP of eth3

Ip addr add 192.168.58.101 dev br100 # add IP of eth3 to the bridge

After reading this article, I believe you have some understanding of "how to use bridging mode to build docker network". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Network container mode configuration host article process watch command finish data more environment user directory knowledge industry equipment information information channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Microsoft Redmi MariaDB macOS