I would like to use ssh-agent to forward my keys into the docker image and pull from a private github repo.
I am using a slightly modified version of https://github.com/phusion/passenger-docker with boot2docker on Yosemite.
ssh-add -l
...key details
boot2docker up
Then I use the command which I have seen in a number of places (i.e. https://gist.github.com/d11wtq/8699521):
docker run --rm -t -i -v $SSH_AUTH_SOCK:/ssh-agent -e SSH_AUTH_SOCK=/ssh-agent my_image /bin/bash
However it doesn't seem to work:
root@299212f6fee3:/# ssh-add -l
Could not open a connection to your authentication agent.
root@299212f6fee3:/# eval `ssh-agent -s`
Agent pid 19
root@299212f6fee3:/# ssh-add -l
The agent has no identities.
root@299212f6fee3:/# ssh git@github.com
Warning: Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hosts.
Permission denied (publickey).
I expanded on @wilwilson's answer, and created a script that will setup agent forwarding in an OSX boot2docker environment.
https://gist.github.com/rcoup/53e8dee9f5ea27a51855
Stick it in
~/bin/docker-run-ssh
,chmod +x
it, and usedocker-run-ssh
instead ofdocker run
.For me accessing ssh-agent to forward keys worked on OSX Mavericks and docker 1.5 as follows:
ssh into the boot2docker VM with
boot2docker ssh -A
. Don't forget to use option -A which enables forwarding of the authentication agent connection.Inside the boot2docker ssh session:
This session must be left open. Take note of the value of the SSH_AUTH_SOCK environmental variable.
In another OS X terminal issue the docker run command with the SSH_AUTH_SOCK value from step 2 as follows:
I don't really like the fact that I have to keep a boot2docker ssh session open to make this work, but until a better solution is found, this at least worked for me.
I ran into a similar issue, and was able to make things pretty seamless by using ssh in master mode with a control socket and wrapping it all in a script like this:
Not the prettiest thing in the universe, but much better than manually keeping an SSH session open IMO.
Socket forwarding doesn't work on OS X yet. Here is a variation of @henrjk answer brought into 2019 using Docker for Mac instead of boot2docker which is now obsolete.
First run a ssh server in the container, with /tmp being on the exportable volume. Like this
Then ssh into this container with agent forwarding
Inside of that ssh session find out the current socket for ssh-agent
Now you can run your real container. Just make sure to replace the value of SSH_AUTH_SOCK below, with the value you got in the step above
This error occurs when
$SSH_AUTH_SOCK
env var is set incorrectly on the host or not set at all. There are various workarounds you could try. My suggestion, however, is to dual-boot Linux and macOS.Additional resources:
By default, boot2docker shares only files under
/Users
.SSH_AUTH_SOCK
is probably under/tmp
so the-v
mounts the agent of the VM, not the one from your mac.If you setup your VirtualBox to share
/tmp
, it should be working.