I have exactly the same issue while building a Docker image. I tried on two different PCs and ended up with the same failure. It seems that the ssh-agent in WSL2 failed to forward into the Docker image. There's another way to pass ssh key safely into docker image,see https://docs.docker.com/build/ci/github-actions/secrets/