If you’re building your docker container to deploy an application, you’d most likely need to pull your git repository code into the container.
Instead of copying your ssh-keys into the container (please don’t), why not use the tried and tested method of ssh-agent forwarding.
To setup ssh-agent forwarding with your docker container, just start your container with this:
docker run --rm -t -i -v $SSH_AUTH_SOCK:/ssh-agent -e SSH_AUTH_SOCK=/ssh-agent my_image /bin/bash
Now you can use your host system’s ssh-keys to pull from your git repositories!
If you’re not sure how to get started, just follow these steps before running the above command.
$ eval $(ssh-agent) $ ssh-add
Now your ssh-key is added to ssh-agent, and your ssh-agent can interact with your docker container to use them for authentication!