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
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 email@example.com:xxx/xxx.git
Here is the error:
Cloning into 'xxx'... Warning: Permanently added the RSA host key for IP address '22.214.171.124' 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?