Correct services hostname configuration

Hi you all!

I’m having some trouble deploying a stack to a local 3-clusters swarm (for now) created with docker-machine.

All services are in the same network and when working locally running docker-compose run.. I have no problem in connecting services using service names as hostname, for instance:

# docker-compose.yml
---
version: '3'

services:
  app:
    build: .
    # ...
    depends_on:
      - db
  db:
    image: postgres:9.6

We are talking about a Ruby application and the database configuration is the following;

# database.yml
---
default: &default
  # ... typical stuff
  username: postgres
  host: postgres # The name of the service in docker-compose.yml
  
development:
  <<: *default
 
production:
  <<: *default
  host: <%= ENV['DATABASE_HOST'] %>
  database: <%= ENV['DATABASE_NAME'] %>
  username: <%= ENV['DATABASE_USERNAME'] %>
  password: <%= ENV['DATABASE_PASSWORD'] %>

AFAIK this looks pretty standard when developing locally. In fact, the app service connects correctly to the postgres service using the service name as hostname. This happens also with a sidekiq service and a rabbitmq one.

The issue, and I’m almost a 100% sure I’m missing something very basic, is that when I the stack is deployed to a swarm, services are not able to see each other, so when I check the logs for some services I see that connections are being refused to the app service.

I’m not pretty sure if I have to configure something in the manager node or this manager is able to manage the routing between hosts names and service names and physical addresses.

I’d really appreciate if someone can put me in the right direction on how to configure services for deploying to a swarm. As I mentioned, this is done in a local swarm with 3 nodes created using docker-machine create... and I already run eval $(docker-machine env manager-node).

Thanks in advance!