Production secrets and rotation
Worked example
This is an offline lesson. Data are fictional and Docker commands are unexecuted. Any optional execution requires an authorized disposable VM, a verified context, synthetic data, restricted access and no external transmission. Do not collect secrets or private output. Use only the fictional worksheet for this exercise. Before a separately authorized read-only server query, verify the effective endpoint including environment overrides, project or cluster identity, and access scope. Never deploy the fragments, use real credentials or transmit private inspection output.
Illustrative Compose fragment (not a complete file):services: app: secrets: - app_token proxy: # no app_token grantsecrets: app_token: file: ./private/app-token.txtFictional rotation plan:issue new token -> update approved source -> reload/recreate consumer-> verify new token -> revoke old token -> record resultThe app must be written to read /run/secrets/app_token; defining a secret alone does not teach an application to use it. The proxy entry above is only a fragment showing lack of a grant. For local Compose, file sources are host files, so restrict their permissions, avoid Git and build contexts, and verify in-container readability by the intended UID. A Compose secret is not protection against the host administrator or all backup leakage. When a provider supports overlapping credentials, verify consumers using the replacement before revoking the old token; otherwise schedule a controlled outage or provider-specific transition. Verify that processes actually reload the value, because a file update does not guarantee application refresh. Log identifiers and outcomes, not secret contents. Local Compose file-backed secrets use a bind mount; long-form uid/gid/mode remapping is not supported for that source. Atomic replacement of a host pathname need not change an existing file mount. Require evidence from each authorized consumer after reload or recreation, and verify upstream revocation separately.
Common mistake
Do not put credentials in the Compose file, Dockerfile ARG, image layer or troubleshooting output. A later deletion cannot guarantee earlier copies vanish.
Manual practice
Plan a rotation for two app instances sharing a fictional token. State how to prove both use the new token without printing it and when the old token may be revoked.
Worksheet: lab-fixtures/docker-production-deployment/04-secrets/scenario.txt.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Production secrets and rotation — Knowledge check
Interpret production deployment evidence and make a safe operational decision.
Does a top-level secret automatically grant all services access?
What does a local file-backed secret still require?
When should the old overlapping token be revoked?