0

I am trying to clone a private repo from a private bitbucket repository. However, my docker build fails since I cannot import rsa key. What is the correct solution here? I am planning to distribute this docker file so that each user can build the docker image. I can see that my image hasn't done the git clone.

DockerFile

FROM debian:9
MAINTAINER jam.gord@yw.com

ARG SSH_PRIVATE_KEY

RUN apt-get update -y

# Update, upgrade and install
RUN apt-get install -y gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat cpio python python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev pylint3 xterm

# Install software 
RUN apt-get install -y git

RUN mkdir -p ~/.ssh && umask 0077 && echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa \


RUN mkdir -p /home/jam \
    cd /home/jam \
    git clone ssh://git@bitbucket.yw.com:7999/ba/yw-linux-build.git

#Set working directory
WORKDIR /home/jam
phd
  • 82,685
  • 13
  • 120
  • 165
  • Does this answer your question? [Use Host SSH keys for private Git repo access in DockerFile](https://stackoverflow.com/questions/53402058/use-host-ssh-keys-for-private-git-repo-access-in-dockerfile) – phd Jan 10 '20 at 09:30
  • https://stackoverflow.com/questions/tagged/docker+ssh-keys – phd Jan 10 '20 at 09:30

1 Answers1

0

use COPY in dockerfile to import rsa key from the host.

COPY id_rsa.pub /home/jam/.ssh
COPY id_rsa /home/jam/.ssh

id_rsa.pub and id_rsa file located in the folder same as dockerfile.

OR

echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa \ 

after this ,remember to set the permisson 600 of id_rsa

clara
  • 182
  • 1
  • 2
  • 13