Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start container with multiple network interfaces

With 1.9, is there a way to start a container directly with two or more network interfaces?

You can do it after the container is started with "docker network connect", but it means the process is already running and might miss the creation of the new one.

like image 624
Robert Avatar asked Dec 05 '15 20:12

Robert


People also ask

Can Docker container have multiple network interfaces?

You can create multiple networks with Docker and add containers to one or more networks. Containers can communicate within networks but not across networks. A container with attachments to multiple networks can connect with all of the containers on all of those networks.

Can you have multiple network interfaces?

Multiple network interfaces let you create configurations in which an instance connects directly to several VPC networks. Each instance can have up to 8 interfaces, depending on the instance's type. For more information, see Maximum number of interfaces.

Can I run multiple services in a container?

It's ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application. You can connect multiple containers using user-defined networks and shared volumes.

How you can give different network IP to the container?

When you connect an existing container to a different network using docker network connect , you can use the --ip or --ip6 flags on that command to specify the container's IP address on the additional network. In the same way, a container's hostname defaults to be the container's ID in Docker.


1 Answers

This question is top doing a search regarding docker and multiple network interfaces. Although is not the required version in the question I leave here some info:

With Docker 1.12+ it's possible to add more than one network interface to a docker container, but it is needed to create the container first and then attach the second (and subsequence) network NICs prior to start the container:

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

It is needed to create the networks 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 

Also, you can start the container attaching the dockerhost network interfaces by using the --network=host argument in docker run:

$ docker run --net=host containerimage:latest 
like image 162
methadata Avatar answered Sep 23 '22 00:09

methadata