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).
A one-liner:
Here’s how to set it up on Ubuntu 16 running a Debian Jessie image:
https://techtip.tech.blog/2016/12/04/using-ssh-agent-forwarding-with-a-docker-container/
Since version
2.2.0.0
, docker for macOS allows users to access the host’s SSH agent inside containers.Here's an example command that let's you do it:
Note that you have to mount the specific path (
/run/host-services/ssh-auth.sock
) instead of the path contained in$SSH_AUTH_SOCK
environment variable, like you would do on linux hosts.