Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use bridging mode to build docker network

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

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!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report