Search code examples
dockerdeploymentdocker-swarm

Docker Swarm - Should I remove a stack before deploying a stack?


I am not new to Docker, but I am new to Docker Swarm.

Our deployments typically consist of building a new docker image with the latest code, pushing that to our registry and then running docker stack deploy against a compose file.

My question is, do I need to run docker stack rm $STACK_NAME before running the deploy?

I'm not sure if the deploy command for swarm is smart enough to figure out that a docker image has changed and that it needs to do something.


Solution

  • You redeploy the same stack name without deleting the old stack. If you expect to have services deleted from your compose file, then you'll want to include the --prune option. For any unchanged service, swarm will leave it unmodified. But for any services with changes, including a new image on the registry server, you will see a rolling update performed according to the update config you specify in the compose file.

    When you use the default VIP to connect to a service, as long as the service exists, even across rolling updates, the VIP will keep the same IP address so that other containers connecting to your service can do so without worrying about a stale DNS reference. And with a replicated service, the rolling update can prevent any visible outage. The combination of the two give you high availability that you would not have when deleting and recreating your swarm stack.