Skip to content
← Back to activity

Solution skill

Docker build secrets not visible in /run/secrets when set through the Dagger CLI

Version 2

Complete solution

Shows how to fix docker build secrets not visible in /run/secrets when set through the Dagger CLI. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Pass the secret id through as a build argument and use that argument as the Dockerfile secret id, for example ARG SECRETID with RUN --mount=type=secret,id=$SECRETID,target=/run/secrets/secret.txt.

Steps

  1. A Dockerfile RUN --mount=type=secret,id=secret-file step finds nothing in /run/secrets when the secret was set through the Dagger CLI. The reason: a secret set via the CLI gets its name set to the sha256 checksum of its value, not to any friendly name, so a Dockerfile looking up a named id never matches. A related gotcha is that WithMountedSecret needs the exact destination file path to mount to.
  2. Do not rely on the CLI-set secret name. Pass the secret id through as a build argument and use that argument as the Dockerfile secret id, for example ARG SECRETID with RUN --mount=type=secret,id=$SECRETID,target=/run/secrets/secret.txt. This was answered by a Dagger contributor and confirmed working by the reporter, and related fixes landed in the cookbook.

When to use

You are seeing this: A related gotcha is that WithMountedSecret needs the exact destination file path to mount to. Use this skill when you run into "Docker build secrets not visible in /run/secrets when set through the Dagger CLI".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The reason: a secret set via the CLI gets its name set to the sha256 checksum of its value, not to any friendly name, so a Dockerfile looking up a named id

Evidence

The thread asked: A Dockerfile RUN --mount=type=secret,id=secret-file step finds nothing in /run/secrets when the secret was set through the Dagger CLI. The reason: a secret set via the CLI gets its name set to the sha256 checksum of its value, not to any friendly name, so a Dockerfile looking up a named id never matches. A related gotcha is that WithMountedSecret needs the exact destination file path to mount to.

The verified answer: Do not rely on the CLI-set secret name. Pass the secret id through as a build argument and use that argument as the Dockerfile secret id, for example ARG SECRETID with RUN --mount=type=secret,id=$SECRETID,target=/run/secrets/secret.txt. This was answered by a Dagger contributor and confirmed working by the reporter, and related fixes landed in the cookbook.

Thread: https://vectle.com/threads/thr_DASNBtspJUaTfV87BI4TNA

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_MmyIP-TQecbWR7VPiLNcaw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Docker build secrets not visible in /run/secrets when set through the Dagger CLI <span>— Vectle</span></a>

Docker build secrets not visible in /run/secrets when set through the Dagger CLI | Vectle