Example of how to start a container with multiple network interfaces using docker

Example of how to start a container with multiple network interfaces using docker

Adding a network interface to the container

1 Run a container with 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 through the image tst_img on the host machine. This container 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 process 1 in the host machine namespace.

3 Add network interface eth1 to the container

(1) Create a pair of veth peer devices

# ip link add veth0 type veth peer name veth1 

After creation, you can see the two newly created devices through "ip link list".

(2) Add the veth end to the bridge

# brctl addif docker0 veth0
# ip link set veth0 up 

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

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

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

Rename the new interface to eth1 and change its IP address.

# ip netns exec $pid ip link set dev veth1 name eth1
# ip netns exec $pid lp link set eth1 up

After the container is up you can do it with "docker network connect", but that means the process is already running and might miss new ones.

This question is a search on docker and multiple network interfaces. Although not the required version I leave some information here:

With Docker 1.12, it is possible to add multiple network interfaces to a docker container, but you first need to create the container, then attach the second (and subsequent) network NICs 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

Additionally, you can start a container with the Dockerhost network interface by using the --network=host parameter in docker run:

$docker run --net=host containerimage:latest

Translated from: http://stackoverflow.com/questions/34110416/start-container-with-multiple-network-interfaces

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:
  • How to implement Docker container self-start
  • Example of how to automatically start an application service in a Docker container
  • Docker practice: error resolution when starting a container from a new image
  • Add port mapping after docker container starts
  • Running Flume in a Docker container and starting it without outputting running logs
  • Docker learning notes: How to view, start, terminate and delete containers
  • How to enter the startup container in Docker
  • The difference between two ways to create a docker image and start the container (summary)
  • Docker uses Dockerfile to create a container image that supports automatic startup of ssh service

<<:  How to use JSX in Vue

>>:  MySql login password forgotten and password forgotten solution

Recommend

JavaScript object-oriented class inheritance case explanation

1. Object-oriented class inheritance In the above...

Innodb system table space maintenance method

Environmental Description: There is a running MyS...

How to use Portainer to build a visual interface for Docker

Portainer Introduction Portainer is a graphical m...

JavaScript to achieve fixed sidebar

Use javascript to implement a fixed sidebar, for ...

Detailed installation and configuration of hadoop2.7.2 under ubuntu15.10

There are many Hadoop installation tutorials on L...

Linux operation and maintenance basic swap partition and lvm management tutorial

Table of contents 1. Swap partition SWAP 1.1 Crea...

js to implement file upload style details

Table of contents 1. Overview 2. Parameters for c...

Util module in node.js tutorial example detailed explanation

Table of contents Starting from type judgment Str...

Detailed explanation of the usage of setUp and reactive functions in vue3

1. When to execute setUp We all know that vue3 ca...

Detailed explanation of the buffer pool in MySQL

Everyone knows that data in MySQL needs to be wri...

Linux kernel device driver kernel time management notes

/****************** * Linux kernel time managemen...

Vue state management: using Pinia instead of Vuex

Table of contents 1. What is Pinia? 2. Pinia is e...

Web development tutorial cross-domain solution detailed explanation

Preface This article mainly introduces the cross-...

A brief discussion on how to write beautiful conditional expressions in JS

Table of contents Multiple conditional statements...

Javascript implements simple navigation bar

This article shares the specific code of Javascri...