2

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!

Saul Martínez
  • 920
  • 13
  • 28
  • Which Docker network the services are using in Swarm? I think you should connect each service to `ingress overlay` network explicitly. – Janshair Khan Aug 15 '17 at 06:55
  • After I deploy the swarm I see a new network is created prefixed with the name of the project. When I inspect the services each one seems to be on a different network(?) as the alias is different and the NetworkID to. This morning I defined a network in the compose file and assigned the network to each individual service. But still, the host is not reachable for the services. – Saul Martínez Aug 15 '17 at 15:13
  • I think that a better way to ask would "In my application, when connecting for example to a Redis host, do I need to put a) the name of the service, b) the IP address of the instance in which the host is running or c) the hostname of the instance the host is running". – Saul Martínez Aug 15 '17 at 15:41
  • I think you are close to A options. Let me know a quick thing that have you connected the services to the same `ingress overlay` network? As the Swarm's service discovery features works within this ingress network. If you haven't tried. Give it a shot. [This](https://www.youtube.com/watch?v=nGSNULpHHZc) video may help you. – Janshair Khan Aug 15 '17 at 17:01

0 Answers0