简体   繁体   English

Docker:如何从本地容器连接到本地群端口

[英]Docker: how to connect from local container to local swarm port

We have swarm running on 6 hosts and about 15 containers. 我们有6台主机和约15个容器在运行。 There are one accesspoint open as port 3010. 有一个接入点作为端口3010打开。

On every host, which are nodes of swarm, there is local isolated network with 3 docker containers. 在作为群集节点的每个主机上,都存在具有3个docker容器的本地隔离网络。 On each host, one of this containers want to connect to that publish port 3010. 在每个主机上,此容器之一要连接到该发布端口3010。

I like to use port on that host, which is currently running that container. 我喜欢在该主机上使用端口,该主机当前正在运行该容器。 I do not know, if this is wise? 我不知道这是否明智?

How to solve the name of host to use on docker container to connect to the local swarm port. 如何解析在Docker容器上用于连接到本地swarm端口的主机名。 Localhost and 127.0.0.1 are not available. Localhost和127.0.0.1不可用。 I can connect container on overlay network on swarm, but it is not possible, when starting container, because of local isolated network. 我可以在群集的覆盖网络上连接容器,但是由于本地隔离的网络,无法启动容器时。

How to solve the name of host to use on docker container to connect to the local swarm port. 如何解析在Docker容器上用于连接到本地swarm端口的主机名。

It the name of your service name. 它是您的服务名称的名称。
Eg when docker service create --name blue --network dev markuman/color 例如,当docker service create --name blue --network dev markuman/color
then you can attache to this service container with figuring out the exactly name id 那么您可以通过确定确切的名称id将其附加到此服务容器

docker ps| grep blueeb46c52d0568        markuman/color:latest   
"/bin/sh -c '/bin/..."   51 seconds ago      Up 49 seconds       80/tcp              blue.1.o5w76smq3kh5jlomltf6yohj3

and simply do 并简单地做

docker exec -ti blue.1.o5w76smq3kh5jlomltf6yohj3 bash

That's it. 而已。 From there you can ping or ssh into other serivces which are assigned to the same network. 从那里,您可以ping或ssh进入分配给同一网络的其他服务。
Eg when docker service create --name apache ... is running in the same network, just do a ping apache . 例如,当docker service create --name apache ...在同一网络中运行时,只需执行ping apache That's sufficient 够了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM