Search code examples
dockerdocker-composedocker-swarm

Multiple site docker swarm with enforced topology


I am building a proof of concept docker swarm based application stack which is intended to evolve a product which is currently deployed to many physical sites and backed by a distributed CDN. The docker compose system I've set up includes a number of different image types which I need to ensure are deployed to each physical location (three copies of each service A, two copies of each service B, at each site for example, each site being several collocated physical machines belonging to the docker swarm) and then others which are deployed only to a central origin location. I'd like to find a way to deploy this with constraints on where the image types end up on the swarm. Is this possible?


Solution

  • Short answer, yes.

    Long answer: use docker compose for managing your cluster, it will ease management. after creating your swarm you can make docker-compose use that swarm by:

    docker-compose -H <docker-swarm-ip:port> up -d
    

    and if you want a container/service to run specifically on a host.

    add the following entry in docker-compose.yml under the service you want to run on that host:

    environment:
      - "constraint:node==<host>"
    

    This is the way i do it now.

    i believe this is also available when you use the run command. Tough i never tried it.