Last active
August 16, 2019 12:23
-
-
Save ridakk/d9046c121940950e61e3509790d0103f to your computer and use it in GitHub Desktop.
using ssh key in docker image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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