Forum Discussion
SSH commit signing inside docker
Docker for Mac can forward $SSH_AUTH_SOCK into any container, all you need to do is add these 'magic' flags:
-v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock -e SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock
A proof of concept:
docker run -v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock -e SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock alpine 'apk add openssh && ssh-add -l'
With the agent socket available in your container, you should be able to set up commit signing as well.
A few caveats:
- $SSH_AUTH_SOCK needs to be set before Docker for Mac launches (so not just your container, but the entire Docker for Mac app). More info on how you can do that here.
- Your local ~/.gitconfig file will not automatically be present in your Docker container, so you should either mount it as a volume or make sure it gets created within the container.
- The SSH agent authorization model works a bit differently with Docker for Mac than you might expect: you'll only authorize Docker once and then every container that has the socket mounted will be authorized to use the key. That's something to keep in mind.