9

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.
5
  • docker0 doesn't look like the name of something you docker network create here; does deleting that setting help? Do you have a specific reason to try to segregate these containers so much?
    – David Maze
    Commented Feb 19, 2020 at 13:26
  • I tried deleting docker0 - it also didnt go thorugh. I am testing it to showcase a demo :-(
    – Nag
    Commented Feb 19, 2020 at 13:28
  • @David, what shoud be given in that case to connect to default network(docker0) and a customer network such as "sample-net"
    – Nag
    Commented Feb 19, 2020 at 13:28
  • if there is a limitation ( and command seems to be correct) - i may need to use "container:" construct to achieve the same ?
    – Nag
    Commented Feb 19, 2020 at 13:31
  • Weirdly, I have notes from last year that suggest that I did manage to use docker run with multiple --network flags, but it doesn't work for me now and I can't find any evidence online that it was ever possible.
    – knuckles
    Commented Apr 23, 2020 at 12:22

1 Answer 1

16

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.