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

Differences in the hr separator between browsers

When making a web page, you sometimes use a dividi...

Detailed troubleshooting of docker.service startup errors

Execute the following command to report an error ...

Detailed explanation of using Docker to build externally accessible MySQL

Install MySQL 8.0 docker run -p 63306:3306 -e MYS...

MySQL log system detailed information sharing

Anyone who has worked on a large system knows tha...

How to configure eureka in docker

eureka: 1. Build a JDK image Start the eureka con...

Take you to understand MySQL character set settings in 5 minutes

Table of contents 1. Content Overview 2. Concepts...

Writing and understanding of arrow functions and this in JS

Table of contents Preface 1. How to write functio...

Detailed explanation of MySQL InnoDB secondary index sorting example

Sorting Problem I recently read "45 Lectures...

Vue network request scheme native network request and js network request library

1. Native network request 1. XMLHttpRequest (w3c ...

MySQL 5.7.18 zip version installation tutorial

The mysql 5.7.18 zip version of MySQL is not like...

How to create a project with WeChat Mini Program using typescript

Create a project Create a project in WeChat Devel...

How to recover deleted MySQL 8.0.17 root account and password under Windows

I finished learning SQL by myself not long ago, a...

Let's deeply understand the event object in js

We know that the commonly used events in JS are: ...

Example of how to deploy Spring Boot using Docker

Here we mainly use spring-boot out of the box, wh...