Latest
Docker 1 min read

Update Swarm Services and Rotate Secrets

Update Swarm Services and Rotate Secrets
Docker · November 8, 2026

Docker lab/version note: use supported Linux-container tools and patched images. Check version compatibility before running the examples. Docker, Swarm and platform-specific deployment steps were not tested live.

What this guide covers

Swarm can replace service tasks gradually and mount secrets as files. Updates, credential changes and persistent storage still need separate checks; changing a container does not automatically update a database password.

Before you start

Use the app_web service from the stack guide. Choose a tested replacement image and keep a known working version. The secret examples are for a disposable demonstration, not a live database credential rotation.

Step 1: Update the image

On the manager, run:

read -r -p 'Approved new image reference including digest: ' NEW_IMAGE
sudo docker service update --with-registry-auth \
  --image "$NEW_IMAGE" \
  --update-parallelism 1 --update-delay 10s \
  --update-order stop-first --update-monitor 30s \
  --update-failure-action rollback --update-max-failure-ratio 0 \
  app_web
sudo docker service ps app_web --no-trunc
sudo docker service inspect app_web --format '{{json .UpdateStatus}}'
sudo docker service logs --tail 80 app_web

Watch task state and application responses. The update uses stop-first ordering, so plan enough remaining capacity. A rollback needs a version compatible with current data.

Step 2: Mount a new secret

Create a test secret and attach it:

umask 077
openssl rand -hex 24 | sudo docker secret create app_password_v1 -
sudo docker service update \
  --secret-add source=app_password_v1,target=app_password,uid=1000,gid=1000,mode=0400 \
  app_web
sudo docker secret ls

The application must be designed to read /run/secrets/app_password. The sample web server does not use this password, so a successful mount is not an authenticated application test. Verify the image user matches the configured UID and GID.

Step 3: Replace the secret

Swarm secrets are immutable. Create a new one and update the service reference:

openssl rand -hex 24 | sudo docker secret create app_password_v2 -
sudo docker service update \
  --secret-rm app_password_v1 \
  --secret-add source=app_password_v2,target=app_password,uid=1000,gid=1000,mode=0400 \
  app_web
sudo docker service ps app_web --no-trunc

For a real credential, update the backend and consumers in a tested order that allows a safe transition. Remove the old secret only after no service needs it.

Step 4: Check storage before moving tasks

A local named volume belongs to one host. A task moved to another host may find a different empty volume with the same name. Use suitable shared storage or placement and recovery plans for stateful work.

Check the result

Check the final image, running tasks, secret access and real application behavior. Keep secret values out of logs. An image rollback does not restore old persistent data.

References

PB
Written by

Parul Bedi

Notes and guides by Parul Bedi.

Up next

Introduce SonarQube to an Existing Project

Sonar November 11, 2026 1 min read
Open post

Conversation

0 comments

No comments yet. Start the conversation below.

Leave a comment

Replying to a comment.
Be kind. Markdown is not supported in comments.