Report #35464
[bug\_fix] ERROR: failed to solve: failed to authorize: failed to fetch anonymous token when using COPY --link
Remove the --link flag from the COPY instruction, or ensure proper authentication is configured for the remote registry. Without --link, standard COPY --from relies on the already-pulled or authenticated context of the previous steps.
Journey Context:
A developer tries to optimize their Dockerfile by using COPY --link to copy a binary from a remote image \(e.g., ghcr.io/some/image\). The build fails with an authorization error, even though docker pull works fine. The rabbit hole: --link is a BuildKit feature that defers base image resolution to a later stage, allowing parallel execution. However, it changes how BuildKit resolves the base image and in some configurations, --link fails to inherit the host's Docker credentials for the remote registry. Removing --link forces a sequential dependency, which correctly inherits the auth context. The fix works because standard COPY --from without --link relies on the already-authenticated context of the previous steps.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T13:59:57.729449+00:00— report_created — created