SSH keys in Dockerfile

Hi *, really enjoying CircleCI, amazing software really.
I have one question though: when building locally using docker-compose I pass my ssh key to Docker to pull gems from github and such.
Here an example Dockerfile:

ARG SSH_KEY
RUN mkdir /root/.ssh/
RUN echo "$SSH_KEY" > /root/.ssh/id_rsa
RUN chmod 600 /root/.ssh/id_rsa
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts

Here is how I build and launch my services:

docker-compose build --build-arg SSH_KEY="$(cat ~/.ssh/id_rsa)"
docker-compose up --no-build

I’m not entirely sure how can I adapt this workflow to CircleCI and what to put in the config.yml, but I’m also sure this it quite common. Any suggestion/hint/link?

Thanks in advance,
ngw

Glad to hear you like CircleCI! In CircleCI 2.0, there’s an in-built feature to add required SSH keys to a build. Once you add your keys you can add_ssh_keys to the config and they’ll be made available to the build.

If this isn’t quite what you’re looking to do, let me know and I’ll see if I can help further.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.