Skip to content

Instantly share code, notes, and snippets.

@ridakk
Last active August 16, 2019 12:23
Show Gist options
  • Save ridakk/d9046c121940950e61e3509790d0103f to your computer and use it in GitHub Desktop.
Save ridakk/d9046c121940950e61e3509790d0103f to your computer and use it in GitHub Desktop.
using ssh key in docker image
# add credentials on build
ARG SSH_PRIVATE_KEY
RUN mkdir /root/.ssh/
RUN echo "${SSH_PRIVATE_KEY}" > /root/.ssh/id_rsa
RUN chmod 600 /root/.ssh/id_rsa
# make sure your domain is accepted
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts
# use as below when building docker image
# docker build -t . --build-arg SSH_PRIVATE_KEY="$(cat <path-to-private-key>)"
# WARNING: not to expose your private key in docker image, use multi stage build and add your key
# WARNING: as `cat` is used this will make private-key visible if stdout is logged or displayed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment