2.9 KiB
2.9 KiB
name, description
| name | description |
|---|---|
| add-docker-secrets | Wire credentials (API keys, tokens, private package-index auth) into a Docker / docker-compose project without baking them into image layers — BuildKit secret mounts for build time, env_file or compose secrets for runtime, plus .gitignore / .dockerignore hygiene checks. Use when the user says "docker secrets", "add a secret", "API key in the container", "token for the build", needs credentials inside a containerized project (e.g. NCBI/Entrez keys, GitHub PAT for private R or Python packages), or asks how to pass secrets into docker build or docker compose. |
add-docker-secrets
When to use
- User says "docker secrets", "add a secret", "/add-docker-secrets".
- A containerized project needs a credential: API key at runtime, or a token to install private packages at build time.
Process
- Classify the secret — build time or runtime?
- Build time: needed only while the image builds (private PyPI
index, GitHub PAT for
renv/remotesinstalls). - Runtime: needed by the running code (NCBI/Entrez key, database password, service token).
- Build time: needed only while the image builds (private PyPI
index, GitHub PAT for
- Build-time → BuildKit secret mount. Never
ARG/ENV:RUN --mount=type=secret,id=gh_pat \ GITHUB_PAT=$(cat /run/secrets/gh_pat) R -e "renv::restore()"
The secret exists only during that# docker-compose.yml services: dev: build: secrets: [gh_pat] secrets: gh_pat: file: ./secrets/gh_pat.txtRUN; it never lands in a layer. - Runtime →
env_file(simple) or composesecrets:(file-based).
Code readsservices: dev: env_file: .env # KEY=value lines, never committedSys.getenv("ENTREZ_KEY")/os.environ["ENTREZ_KEY"]— no fallback default containing a real value. - Hygiene check — all three must hold before finishing:
.env,secrets/in.gitignore..env,.env.*,secrets/in.dockerignore(soCOPY . .can't leak them into a layer).docker history <image>shows no secret in any layer command.
- Provide a
.env.examplewith placeholder values so the required keys are documented without the values.
Output / done criteria
- Secret reaches the build or the process, and
docker historyplusgit statusshow no trace of its value. .env.examplelists every required key.
Guardrails
- Never pass secrets via
ARGorENVin a Dockerfile — both persist in image metadata and layer history. - Never
COPYa file containing a secret into any stage. - Never commit
.envorsecrets/; check.gitignorebefore writing them. - Never echo a secret value into logs, justfile recipes, or compose
environment:literals.
See also
../containerize-project/SKILL.md— the three-stage setup this hardens; its.dockerignoretemplates already exclude.envand.env.*.