I'm looking to forwarding my ssh-agent and found this https://github.com/nardeas/ssh-agent
and the steps are the following
0. Build Navigate to the project directory and launch the following command to build the image:
docker build -t docker-ssh-agent:latest -f Dockerfile .
1. Run a long-lived container
docker run -d --name=ssh-agent docker-ssh-agent:latest
2. Add your ssh keys Run a temporary container with volume mounted from host that includes your SSH keys. SSH key id_rsa will be added to ssh-agent (you can replace id_rsa with your key name):
docker run --rm --volumes-from=ssh-agent -v ~/.ssh:/.ssh -it docker-ssh-agent:latest ssh-add /root/.ssh/id_rsa
The ssh-agent container is now ready to use.
3. Add ssh-agent socket to other container: If you're using docker-compose this is how you forward the socket to a container:
volumes_from:
- ssh-agent
environment:
- SSH_AUTH_SOCK=/.ssh-agent/socket
in a compose file, I add step 1 to it like so:
services:
ssh_agent:
image: nardeas/ssh-agent
However I do not what's the equivalent syntax in compose file for step 2
docker run --rm --volumes-from=ssh-agent -v ~/.ssh:/.ssh -it docker-ssh-agent:latest ssh-add /root/.ssh/id_rsa