Docker Swarm · Lesson 6 of 10 · 3 min read
Secrets and configs
Swarm secrets
printf 's3cr3t' | docker secret create db_password_v1 -
docker secret ls
docker service create --name api --secret source=db_password_v1,target=db_password app
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
How they're protected:
- Stored encrypted in the Raft log on managers.
- Sent only to nodes running a task that's been granted the secret, over mutual TLS.
- Mounted into the container as an in-memory tmpfs file at
/run/secrets/<target>— never written to the node's disk, removed when the task stops. - Not visible in
docker inspector environment variables.
Secrets are immutable. Rotation pattern:
printf 'n3wp4ss' | docker secret create db_password_v2 -
docker service update \
--secret-rm db_password_v1 \
--secret-add source=db_password_v2,target=db_password api
docker secret rm db_password_v1
Keeping the same target means the app's path doesn't change; the update triggers a rolling restart.
Configs
Configs use the same mechanism for non-sensitive files (nginx.conf, app settings) and can be mounted at any path. They're also immutable and rotated the same way. Unlike secrets, they're not encrypted at rest.