Docker "RUN --mount=type=ssh" - "SSH agent not available" / "no ssh forwarded"
A RUN --mount=type=ssh needs an SSH agent forwarded into the build with --ssh. BuildKit reports the agent is not available because either --ssh was not passed or no agent is running on the runner.
What this error means
A build that clones a private repo over SSH fails on the RUN --mount=type=ssh step with SSH agent not available or a downstream Permission denied (publickey). The Dockerfile is correct; the SSH socket was never forwarded.
ERROR: failed to solve: SSH agent not available; make sure to use
"docker build --ssh default" and have an ssh-agent running
# or the clone itself fails: git@github.com: Permission denied (publickey)Diagnose it: build context, cache, or platform?
A Dockerfile that builds locally and fails in CI usually differs in one of three ways: the build context contains different files, the layer cache is cold or poisoned, or the runner architecture does not match what the base image provides.
# what is actually being sent as build context (dockerignore applies)
docker build --no-cache --progress=plain -t probe . 2>&1 | head -40
# what platform are you on, and what does the base image support?
docker version --format '{{.Server.Arch}}'
docker buildx imagetools inspect <base-image> | grep -i platform
# prove it is not a cache artefact
docker build --no-cache .Common causes
No --ssh passed to the build
The mount forwards an agent socket only when --ssh default (or --ssh id=...) is on the build command. Without it, the mount has no agent to expose.
No ssh-agent running on the runner
Even with --ssh default, there must be a live agent holding the key. A fresh CI shell has no agent until you start one and add the deploy key.
build-push-action ssh input missing
With docker/build-push-action, the ssh: input must request default; omitting it means no socket is forwarded.
How to fix it
Start an agent, add the key, and forward it
Load the deploy key into an agent, then pass --ssh default to the build.
eval "$(ssh-agent -s)"
ssh-add - <<< "$DEPLOY_KEY"
docker build --ssh default .Forward SSH in build-push-action
Use the action’s ssh-agent setup, then request the default socket.
- uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
- uses: docker/build-push-action@v6
with:
ssh: defaultKeep the build context small and deterministic
- A missing
.dockerignoresendsnode_modules,.git, and build output to the daemon, which is slow and can change layer hashes between environments. - A
COPYof a path that exists locally but is gitignored will fail in CI, because the runner only has what the checkout produced. - Multi-arch builds need
buildxand QEMU set up explicitly; a plaindocker buildon an ARM runner silently produces an ARM image.
How to prevent it
- Always pair
RUN --mount=type=sshwith--ssh defaultand a running agent. - Load the deploy key into the agent before the build step.
- Prefer SSH forwarding or build secrets over copying keys into the image.