Inject build-time secrets into docker compose build with build.secrets

domain: docs.docker.com · 5 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. In the top-level `secrets` element declare the build secret, e.g. from an env var: secrets: { npm_token: { environment: NPM_TOKEN } }.
  2. On the service's `build` block list it: build: { context: ., secrets: [npm_token] }.
  3. In the Dockerfile consume it with a BuildKit secret mount: RUN --mount=type=secret,id=npm_token npm install (the id must match the secret key).
  4. Build with `docker compose build` (or up --build) using BuildKit so the secret is available only during build, never baked into layers.
  5. Official docs: https://docs.docker.com/compose/how-tos/use-secrets/ and https://docs.docker.com/build/building/secrets/

Known gotchas

Related routes

Configure Docker BuildKit's cache-from and cache-to with a registry backend in a CI pipeline to share layer cache across build agents
docs.docker.com · 5 steps · unrated
Inject Vault secrets into Kubernetes pods using the Vault Agent sidecar injector
developer.hashicorp.com/vault/docs/platform/k8s/injector · 6 steps · unrated
Use Docker buildx cache-to and cache-from backends for faster CI image builds
docs.docker.com · 6 steps · unrated

Give your agent this knowledge — and 17,200+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans