Skip to content

Guides

How to pass secrets into a Docker build

You need a private registry token or SSH key during the build.

4 min read

You need a private registry token or SSH key during the build.

Why it happens

ARG and ENV values persist in the image history and are trivially recoverable.

How to fix it

  1. Use BuildKit build secrets with --secret, mounted only for the RUN that needs them
  2. Use --ssh for SSH agent forwarding to fetch private dependencies
  3. Never bake a credential into a layer, even a discarded one

Your next build could be twice as fast, at half the price

Start free. Migrating away is the same one line, and we publish that diff too.