Search code examples
dockerdocker-composedockerfiledocker-swarmauto-update

Self updating docker stack


I have a docker stack deployed with 20+ services which comprise my application. I would like to know that is there a way to update this stack with the latest changes to the software from within one of the containers running as a part of the stack?

Approach i have tried:

  1. In one of the containers for a service, mounted the docker socket and the /usr/bin/docker file and downloaded the latest compose file from the server.
  2. Instantiated a script which downloads the latest images
  3. Initiate a docker stack deploy with the new compose file

Everything works fine this way but if the service which is running this process itself has an update and if that docker stack deploy tries to create this service before any other service in the stack, then the stack update fails. Any suggestion or alternative approaches for this?


Solution

  • There is no out of the box solution for docker swarm mode (something like watchtower for single docker). I think you already found the best solution for doing this automatically. I would suggest you put the update container (the one that is updating the services) on a ignore list. Then on one of your master nodes, create a cron that updates that one container. I know this is not a prefect solution, but it should work.