Docker - 容器无法连接到网络端点

标签 docker

通过附加到网络接口(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”与所有其他容器连接起来。但是,我在执行命令时遇到了错误
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

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.


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

相关文章:

image - 使 Docker 镜像相互通信

代理背后的 Docker Centos 7 easy_install supervisor ssl 问题

docker - 在没有Docker守护程序的情况下调用Docker API

python - Apache Airflow 无法连接到本地主机数据库

docker - 如何使用 docker 配置 iptables 策略以阻止外部 ip

docker - 有没有办法在构建 Docker 镜像时抑制 "update-alternatives: warning: skip creation"警告?

mongodb - docker mongodb 配置文件

docker - 使用多阶段 docker 文件输出多个图像

docker - 链接数据剧院| standard_init_linux.go:195:导致 “no such file or directory”的exec用户进程

git - 在构建/运行时将参数列表传递给 docker