Docker swarm containers communication

i create a swarm and join a node, very nice all works fine
docker swarm init --advertise-addr
docker swarm join --token verylonggeneratedtoken

i create 3 services on the swarm manager
docker service create --replicas 1 --name nginx nginx --publish published=80,target=80
docker service create --replicas 1 --name php php:7.1-fpm published=9000,target=9000
docker service create --replicas 1 --name postgres postgres:9.5 published=5432,target=5432

All services boots up just fine, but if i customize the php image with my app, and configure nginx to listen to the php fpm socket i can’t find a way to comunicate these three services. Even if i access the services using “docker exec -it service-id bash” and try to ping the container names or host names (i even tried to curl them).
What i am trying to say is i don’t know how to configure nginx to connect to fpm since i don’t know how one container comunicates to another using swarm. Using docker-compose or docker run is simple as using a links option. I’ve read all documentation around, spent hours on trial and error, and i just couldn’t wrap my head around this. I have read about the routing mesh, wish will get the ports published and it really does to the outside world, but i couldn’t figure in wish ip its published for the internal containers, also that cant be an ramdom ip as that will cause problems to manage my apps configuration, even the nginx configurations.

Hope this isn’t a very basic question.

Use version 3.0 and up of the docker-compose and use docker swarm deploy this will allow you to connect to each service using their names as a the host names.

Hi jhonatanteixeira,

I see you as a beginner in using Docker swarm please follow this link you may get good idea of using docker swarm using docker stack deploy.