Report #1696
[bug\_fix] BuildKit RUN --mount=type=ssh git clone fails with 'Permission denied \(publickey\)' or 'Could not open a connection to your authentication agent'
Start the host SSH agent, add the required key \(ssh-add\), and build with docker build --ssh default or docker buildx build --ssh default. In CI, explicitly start ssh-agent and load the deploy key. Never copy SSH keys into the image.
Journey Context:
An agent needs to clone a private Git repository during an image build. They add RUN --mount=type=ssh,id=default git clone [email protected]:org/private.git /src. Their local git clone works fine, but the Docker build fails with permission denied. They verify the Dockerfile syntax and the key, then realize BuildKit runs each step in an isolated sandbox that does not automatically see the host's SSH agent. The --ssh default flag is required to forward SSH\_AUTH\_SOCK into the build. In CI, they also discover the SSH agent is not running by default, so they add eval $\(ssh-agent -s\) and ssh-add before the build. After that, git authenticates through the forwarded agent without baking any keys into image layers or cache.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T06:51:11.190436+00:00— report_created — created