-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Description
Sorry if this is a duplicate. I feel like I'm asking a dumb question but I couldn't figure this out even with all the documentation and tutorials. I think it would be great if the answer went into another page of this tutorial.
In docker 1.12.0-rc3 I set up 3 nodes in swarm mode and an overlay network.
I notice the task names are predictably networktest.1, .2, .3:
$ docker service tasks networktest
ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE
d6naj58s8izkb822fpd4b6tl0 networktest.1 networktest alpine Running 4 seconds Running ip-172-31-47-32.us-west-2.compute.internal
7sglm20hhbmn1ws5fiqvqfgx5 networktest.2 networktest alpine Running 4 seconds Running ip-172-31-43-158.us-west-2.compute.internal
au4unlfyavw5y6vhodaw2dwe4 networktest.3 networktest alpine Running 4 seconds Running ip-172-31-43-158.us-west-2.compute.internal
but the container names have a random suffix:
[ec2-user@ip-172-31-47-32 ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e67110a596b0 alpine:latest "sleep 36000" 5 minutes ago Up 5 minutes networktest.1.d6naj58s8izkb822fpd4b6tl0
and
[ec2-user@ip-172-31-43-158 ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
412ed90a1cd7 alpine:latest "sleep 36000" 4 minutes ago Up 3 minutes networktest.2.7sglm20hhbmn1ws5fiqvqfgx5
44ea273ba889 alpine:latest "sleep 36000" 4 minutes ago Up 3 minutes networktest.3.au4unlfyavw5y6vhodaw2dwe4
How are we then supposed to have container-to-container communication?
So giving that full randomly-generated name allows one container to ping another:
[ec2-user@ip-172-31-47-32 ~]$ docker exec -it e67110a596b0 ping networktest.2.7sglm20hhbmn1ws5fiqvqfgx5
PING networktest.2.7sglm20hhbmn1ws5fiqvqfgx5 (10.0.0.4): 56 data bytes
64 bytes from 10.0.0.4: seq=0 ttl=64 time=0.319 ms
64 bytes from 10.0.0.4: seq=1 ttl=64 time=0.236 ms
64 bytes from 10.0.0.4: seq=2 ttl=64 time=0.217 ms
But I really wish this worked too:
[ec2-user@ip-172-31-47-32 ~]$ docker exec -it e67110a596b0 ping networktest.2
ping: bad address 'networktest.2'
I didn't see any parameters to docker service create for links, so how do I configure one container to communicate with another?
In this blog it implied the frontend and redis database would be connected with just the following commands. Was that misleading?
docker network create -d overlay mynet
docker service create --name frontend --replicas 5 -p 80:80/tcp --network mynet mywebapp
docker service create --name redis --network mynet redis:latest