1

How can i run a docker stack (from a docker-compose.yml) on a single docker swarm node which automatically starts on system reboots?

I am using docker-compose to compose my application of multiple services and then use docker stack deploy to deploy it on my server to a single instance docker swarm instance.

In my docker-compose.yml i have defined my services with a restart policy:

deploy:
  restart_policy:
    condition: any
    delay: 5s
    max_attempts: 3
    window: 120s
  placement:
    constraints: [node.role == manager]

which imho should force the service to always run/restart. But when the server/docker daemon is restarted the services are not started. Is there some easy way to do this?

docker service list would show:

ID                  NAME                                 MODE                REPLICAS            IMAGE                                                                              PORTS
s9gg88ul584t        finalyzer-prod_backend               replicated          0/1                 registry.gitlab.com/hpoul/finalyzer/finalyzer-backend:latest                       *:8081->8080/tcp
vb9iwg7zcwxd        finalyzer-prod_mongoadmin            replicated          0/1                 mrvautin/adminmongo:latest                                                         *:8082->1234/tcp
qtasgtqi7m0l        finalyzer-prod_mongodb               replicated          0/1                 mongo@sha256:232dfea36769772372e1784c2248bba53c6bdf0893d82375a3b66c09962b5af9      
wdnrtlbe8jpw        finalyzer-prod_pgdb                  replicated          0/1                 postgres@sha256:73d065c344b419ce97bba953c7887c7deead75e0998053518938231cd7beb22c   

so it recognizes that it should run 1 node, but it does not scale it up. What is the right way to force docker swarm, service or docker stack to scale all configured services up to their configured values upon a server restart, (or docker daemon restart)?

Herbert Poul
  • 4,512
  • 2
  • 31
  • 48
  • run `docker service ps finalyzer-prod_backend` and tell me what is says – Constantin Galbenu Sep 04 '18 at 12:36
  • No need to define a container restart policy with swarm mode, I've seen it conflict with swarm's built-in functionality. – BMitch Sep 04 '18 at 13:15
  • @ConstantinGalbenu well i've now restarted it manually.. https://d.pr/ClfTEE the one i've started `Running 5 hours ago` - the one before `Failed 5 hours ago "task: non-zero exit (255)` but i have verified that this one was the process before the server rebooted (i checked the logs using `docker service logs whh7qe94jppd`) – Herbert Poul Sep 04 '18 at 14:19

0 Answers0