I have a repo set up in github to pull into a docker build. I want to add my keys so I can connect to git but I'm unsuccessfully adding the key file. The error:
id_rsa: no such file or directory
The file exists in the dir specified in the Dockerfile. I tried linking my local file to the docker enviroment with ln command but I get the same error. Here's the docker statements:
RUN mkdir /root/.ssh && ln -s /Users/e002678/.ssh /root/.ssh
RUN touch /root/.ssh/known_hosts
ADD id_rsa /root/.ssh/id_rsa
RUN adduser git
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
In a variant attempt I tried adding a shared volume with the same results:
VOLUME ["/Users/e002678/.ssh"]
ADD /Users/e002678/.ssh/id_rsa /root/.ssh/id_rsa
Thanks!
Docker ADD only works relative to the Dockerfile directory.
For ADD /Users/e002678/.ssh/id_rsa /root/.ssh/id_rsa
to work, you need a source directory like:
$ ls
./Dockerfile
./Users/e002678/.ssh/id_rsa
Tip ADD
copies files "with metadata," i.e. files are copied with the exact same user id, same group id, and same permissions. So explicitly chown/chmod keys after adding them:
ADD ./Users/e002678/.ssh/id_rsa /root/.ssh/id_rsa
RUN chown root: /root/.ssh/id_rsa && chmod 600 /root/.ssh/id_rsa
Pro Tip Docker ADD
creates any needed directories in a path, so RUN mkdir
instructions are unnecessary.