Inject SSH agent keys into Docker on Windows
Sharing the Microsoft SSH agent pipe with a container on Windows is not possible so we'll use Putty SSH agent pageant.exe.
- Install and launch pageant.exe
- Set
SSH_AUTH_SOCKenvironment variable :$env:SSH_AUTH_SOCK="\\.\pipe\"+(get-childitem -Filter pageant* \\.\pipe\ -Name) - Add the key to the agent :
ssh-add.exe C:\Users\%username%\.ssh\id_ed25519 - Run the container :
docker run -it --isolation=hyperv --mount type=npipe,source=$env:SSH_AUTH_SOCK,target='\\.\pipe\openssh-ssh-agent' -e SSH_AUTH_SOCK='\\.\pipe\openssh-ssh-agent' mcr.microsoft.com/windows/servercore:ltsc2025 powershell
Once inside the container, check if it works :
PS C:\> echo $env:SSH_AUTH_SOCK
\\.\pipe\openssh-ssh-agent
PS C:\> ssh-add.exe -l
[...key should appear here...]
PS C:\> git config --global core.sshCommand "C:/Windows/System32/OpenSSH/ssh.exe"
PS C:\> git clone git@github.com:org/repo.git
Cloning into 'repo'...
remote: Enumerating objects: 11178, done.
[...Git can clone using the SSH key...]