Dockerfile git clone ssh repository

  clone, dockerfile, git

I try to git clone a ssh repository on my dockerfile, but I get an error

RUN apt-get install -y git
RUN mkdir /root/.ssh/
ADD id_rsa /root/.ssh/id_rsa
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan gitlab.com >> /root/.ssh/known_hosts

RUN git clone [email protected]:User/repo.git

I don’t want to set my ssh key on gitlab or a file. I want dockerfile fetch my local ssh key ~/.ssh
I succeed with docker run -v ~/.ssh:/root/.ssh -ti id_image bash
but on my docker I have to make manually git clone.

So how I can git clone on my dockerfile directly please.

Source: Dockerfile Questions

LEAVE A COMMENT