1
I'm building a docker image, and I want to clone a repository from bitbucket.
If I create a `debian' container and execute step-by-step, everything works fine. But when I try to create the image, it does not work.
I have added the key to bitbucket settings.
Here is my Dockerfile
FROM debian:stretch
RUN apt-get update && apt-get -y upgrade && apt-get -y install nginx curl software-properties-common gnupg git
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs
RUN mkdir /backend
RUN npm install pm2 ts-node -g
WORKDIR /backend
RUN mkdir /root/.ssh
RUN echo -e "-----BEGIN RSA PRIVATE KEY-----\n(...)-----END RSA PRIVATE KEY-----" >> /root/.ssh/id_rsa
RUN chmod 400 /root/.ssh/id_rsa
RUN ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts
RUN git clone git@bitbucket.org:xxx/xxx.git
Here is the error:
Cloning into 'xxx'...
Warning: Permanently added the RSA host key for IP address '104.192.143.3' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
How can I create this image to work properly?
1To be paranoid, you might say
touch /root/.ssh/id_rsa && chmod 600 /root/.ssh/id_rsa && echo -e "-----BEGIN RSA PRIVATE KEY-----\n(...)-----END RSA PRIVATE KEY-----" >> /root/.ssh/id_rsa
, to avoid having the sensitive data in a world-readable file for even a microsecond. – Scott – 2019-04-26T04:56:28.573