Docker Ssh Keys for Github
Docker project uses library from private Github repo. You need to have access to the repo to build. There are different ways to manage your deploy keys. We are going to generate a keypair and add it to the repo that holds our dependency.
Make a new .ssh
directory in at the same level as your Dockerfile. Then generate your keypair, but ensure that you are creating the keys in that directory.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Next, if the created .ssh
directory has the following path /Users/goliatone/DEV/menagerie/.ssh
, then when you are prompted for the file to save the key just type that path:
Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
One you have created the keys, you have to remove the pass phrase. From your project's root directory:
openssl rsa -in ./.ssh/id_rsa -out ./.ssh/id_rsa
Then, add the following to your Dockerfile
:
ADD .ssh/id_rsa /root/.ssh/id_rsa
RUN ssh-keyscan -t rsa -T 60 github.com > /root/.ssh/known_hosts
RUN echo "IdentityFile ~/.ssh/id_rsa" >> /etc/ssh/ssh_config