Docker-容器无法连接到网络端点 [英] Docker - Container cannot be connected to network endpoints

查看:172
本文介绍了Docker-容器无法连接到网络端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过连接到网络接口test-net,sample-net,bridge0来运行容器时,出现以下错误.我的要求是要有一个容器,该容器可以连接到位于不同网络中的不同容器.

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

我的意图是通过连接到其他所有容器的接口来连接"c5".但是,我在执行命令时遇到错误

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.

推荐答案

似乎无法通过一次连接到多个网络来启动容器.

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

从页面 https://success.docker.com/article/multiple-docker-networks

Docker仅允许通过docker指定单个网络运行命令.要连接多个网络,"docker network connect"是用于连接其他网络.如果需要一个容器在运行之前已连接到多个网络,则可以将网络连接到尚未启动的已创建容器.

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)-

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

这篇关于Docker-容器无法连接到网络端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆