简体   繁体   中英

Docker: how to connect from local container to local swarm port

We have swarm running on 6 hosts and about 15 containers. There are one accesspoint open as port 3010.

On every host, which are nodes of swarm, there is local isolated network with 3 docker containers. On each host, one of this containers want to connect to that publish port 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. Localhost and 127.0.0.1 are not available. 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.

It the name of your service name.
Eg when docker service create --name blue --network dev markuman/color
then you can attache to this service container with figuring out the exactly name 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.
Eg when docker service create --name apache ... is running in the same network, just do a ping apache . That's sufficient

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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