I am trying to write a docker file for an angular cli project, but I have an external dependency that is a private repo on BitBucket, so I need to transfer my ssh key. I am trying to pass ssh keys using--build-arg
Now the problem is that it does not add these keys to ssh-agent and asks for a password instead.
I use this command to run
docker build -t ng-2-docker/client --build-arg ssh_prv_key="$(cat ~/.ssh/id_rsa)" --build-arg ssh_pub_key="$(cat ~/.ssh/id_rsa)" .
and this is my docker file
ARG ssh_prv_key
ARG ssh_pub_key
FROM node:8.9.4
WORKDIR /app
RUN mkdir -p /ssh/
RUN chmod 0700 /ssh
RUN echo "$ssh_prv_key" > /ssh/id_rsa && echo "$ssh_pub_key" > /ssh/id_rsa.pub && chmod 600 /ssh/id_rsa && chmod 600 /ssh/id_rsa.pub
RUN ssh-keyscan bitbucket.org > /ssh/known_hosts
RUN ls -la /ssh
RUN eval `ssh-agent -s` && ssh-add /ssh/id_rsa
COPY package.json /app
RUN npm i
COPY . /app
CMD ["npm", "docker:rogers:local"]
RUN rm -rf /ssh
EXPOSE 4200
and here is the result if I ran the above command.
source
share