Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - Container cannot be connected to network endpoints

Tags:

docker

I am getting the following error when running a contaner by attaching to network interfaces test-net, sample-net,bridge0 . My requirement is to have a container that connects to different containers those are in different networks.

    docker network create --driver bridge sample-net
    docker container run --name c3 -d --network test-net alpine:latest ping 127.0.0.1
    docker network create --driver bridge --subnet "10.1.0.0/16" test-net
    docker container run --name c4 -d --network test-net alpine:latest ping 127.0.0.1

    docker container run --name c1 -it --rm alpine:latest sh
    docker container run --name c5 -d --network sample-net --network test-net --network docker0 alpine:latest ping 127.0.0.1

My intention is to connect "c5" with all other containers by connecting to their interfaces. However , I am facing the error while executing the command

docker container run --name c5 -d --network sample-net --network test-net --network docker0 alpine:latest ping 127.0.0.1

   docker: Error response from daemon: Container cannot be connected to network endpoints: sample-net, test-net, docker0.
like image 460
Nag Avatar asked Dec 31 '22 07:12

Nag


1 Answers

It doesnt seem possible to start a container by connecting to multiple networks at once.

From the page https://success.docker.com/article/multiple-docker-networks

Docker only allows a single network to be specified with the docker run command. To connect multiple networks "docker network connect" is used to connect additional networks. If a container needs to be connected to multiple networks before it runs then it is possible to attach networks to a created container that has not started yet.

And to connect to the default network - in the following example , alpine4 is connected to the default network (along with apline-net) - https://docs.docker.com/network/network-tutorial-standalone/

docker run -dit --name alpine4 --network alpine-net alpine ash
docker network connect bridge alpine4
like image 178
3 revs Avatar answered May 19 '23 10:05

3 revs