Home Linux Containers
Define the service creating a docker-compose yml file

version: "1"
services:
  web:
    image: USERNAME/REPO:TAG
    deploy:
      replicas: 5
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    ports:
      - "4000:80"
    networks:
      - webnet
networks:
  webnet:


Before deploying a service on a host it must be part of a swarm

docker swarm init


Running the service

docker stack deploy -c DOCKER-COMPOSE.yml SERVICE_NAME


View the running service

docker service ls
docker service ps SERVICE_NAME_web


Find the id of each containers running the service

docker container ls -q


To scale up or down the service change the number of replicas in the yml file and re deploy.

docker stack deploy -c DOCKER-COMPOSE.yml SERVICE_NAME

Adding does not kill and restart all, it adds the extra replicas
Removing seem to remove from the bottom of docker service ps SERVICE_NAME_web. The last ones deployed. 

Take down the whole service

docker stack rm SERVICE_NAME


Leave the swarm

docker swarm leave 
docker swarm leave --force