Rollback Procedures
Quick Rollback
Section titled “Quick Rollback”Docker Swarm keeps track of the previous service state. To roll back to the previous version:
docker service rollback dev_service-nameThis reverts the service to its previous image and configuration.
Manual Rollback to a Specific Version
Section titled “Manual Rollback to a Specific Version”If you need to go back to a specific image tag:
-
Find the previous image in Harbor at
https://harbor.ayinza.devor check the git commit SHA -
Update to the previous image:
Terminal window docker service update \--image harbor.ayinza.dev/library/service-name:previous-tag \--with-registry-auth \dev_service-name -
Verify the rollback:
Terminal window docker service ps dev_service-namedocker service logs -f dev_service-name --tail 50
Rollback an Entire Stack
Section titled “Rollback an Entire Stack”If a full stack deploy went wrong, re-deploy with the previous version of the stack file:
# If you have the previous YAML (check git history)git log --oneline /home/kaks/stacks/infrastructure.ymlgit checkout HEAD~1 -- /home/kaks/stacks/infrastructure.ymldocker stack deploy -c /home/kaks/stacks/infrastructure.yml devAutomatic Rollback Protection
Section titled “Automatic Rollback Protection”Docker Swarm has built-in protection against failed updates. When a new container fails to start or its health check fails, Swarm will not kill the existing healthy container. The old working container keeps serving traffic while the new one is rejected.
This means a bad deployment does not break a running service — the previous healthy version stays in place.
# You can see this in action — failed tasks show "Shutdown" while the old one stays "Running"docker service ps dev_apiThis is one of the key safety nets of Docker Swarm: a failed update rolls back automatically, so a broken image push won’t take down a service that was working fine.
Preventing Bad Deployments
Section titled “Preventing Bad Deployments”- Check service logs immediately after deployment
- Use
docker service psto verify new containers are running and healthy - Monitor the service for a few minutes after deployment
- If the service keeps restarting (crashloop), roll back immediately