Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to start multiple network interfaces in docker

Shulou Source: shulou.com Published: 2022-06-01 20:16:08 11月12日 Update

This article introduces how to start multiple network interfaces in docker, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.

Add a network interface to the container

1 runs a container in the default network mode

# docker run-- name tst_add_inf-it tst_img / bin/bash

In this way, we create a container named tst_add_inf from the mirror tst_img on the host machine, which has created a network interface eth0 by default.

2 get the PID of the container

# docker inspect-f'{{.State.Pid}} 'tst_add_inf

The PID of the container obtained above is the process PID of Container No.1 process in the host machine namespace.

3 add the network interface eth2 to the container

(1) create a pair of veth peer devices

# ip link add veth0 type veth peer name veth2

Once created, you can see the two devices you just created through "ip link list".

(2) add veth to the bridge

# brctl addif docker0 veth0# ip link set veth0 up

(3) Associate the other end of the veth with the container

# ln-s / proc/$pid/ns/net / var/run/netns/$container_id# ip link set veth2 netns $pid

(4) configure the newly added network interface of the container

Rename the new interface to eth2 and modify its IP address.

# ip netns exec $pid ip link set dev veth2 name eth2# ip netns exec $pid lp link set eth2 up

After the container starts, you can use docker network connect, but this means that the process is already running and may miss the new one.

This question is about the search of docks and multiple network interfaces. Although not the required version of some information before I leave here:

With Docker 1.12, you can add multiple network interfaces to the docker container, but you first need to create the container, and then attach a second (and subsequent) network NIC before starting the container:

$docker create-network=network1-name container_name containerimage:latest$docker network connect network2 container_name$docker start container_name

You need to create a network first:

$docker network create-- driver=bridge network1-- subnet=172.19.0.0/24$ docker network create-- driver=bridge network2-- subnet=172.19.1.0/24

In addition, you can start the container of the Dockerhost network interface using the-network = host parameter in the docker operation:

Docker run-net=host containerimage:latest on how to start multiple network interfaces in docker to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Container network interface multiple process run one end content host more machine device help yes two information interest parameter can pass name Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MariaDB MySQL vpn Microsoft