IntermediateLesson 15 of 26
Configuration and secrets
Never bake secrets into an image.
Anything in an image layer can be recovered with docker history or by extracting the image, even if a later layer deletes it.
- Pass configuration at runtime with
-e,--env-fileor Composeenvironment. - For build-time secrets use BuildKit secret mounts:
dockerfile
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm cibash
docker build --secret id=npmrc,src=$HOME/.npmrc .- In production use your platform's secret store (Docker/Swarm secrets, Kubernetes Secrets, a vault).