通过附加到网络接口(interface) test-net, sample-net,bridge0 运行容器时,我收到以下错误。
我的要求是有一个容器可以连接到不同网络中的不同容器。

    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

我的目的是通过连接到所有其他容器的接口(interface)将“c5”连接到它们的接口(interface)。但是,我在执行命令时遇到了错误
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.

最佳答案

通过一次连接到多个网络来启动容器似乎是不可能的。
从页面 https://success.docker.com/article/multiple-docker-networks

并连接到默认网络 - 在以下示例中,alpine4 连接到默认网络(与 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

关于Docker - 容器无法连接到网络端点,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60301221/

10-15 22:27