0

I have created a ssh key using ssh-keygen and added id-rsa.pub content to my github>settings>SSH & GPG keys. I am able to clone the repo from my terminal with git clone git@github:myname/myrepo.git

But the same is giving the following error while building the docker file.

Cloning into 'Project-Jenkins'...
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

This is how I added the command in dockerfile

RUN git clone git@github.com:myname/myrepo.git

What went wrong here?

here is my dockerfile

FROM ubuntu
COPY script.sh /script.sh
CMD ["/script.sh"]
FROM python:2.7
RUN apt-get update 
RUN apt-get install libmysqlclient-dev
RUN apt-get install -y cssmin
RUN apt-get install -y python-psycopg2
RUN pip install --upgrade setuptools
RUN pip install ez_setup
RUN apt install -y libpq-dev python-dev
RUN apt install -y postgresql-server-dev-all
COPY requirements.txt ./
CMD ["apt-get","install","pip"]
RUN apt-get install -y git
RUN git clone git@github.com:myname/myrepo.git
WORKDIR ./myrepo/LIMA
RUN pip install -r requirements.txt
CMD ["python","manage.py","migrate"]
CMD ["python","manage.py","collectstatic","--noinput"]
CMD ["python","manage.py","runserver"]
EXPOSE 8000

1 Answers1

1

The syntax you have used finally ends up using SSH to clone, and inside the docker container, your github private key is not available which leads to error that you are getting. So instead try using,

RUN git clone https://{myusername}:{mypassword}@github.com/{myusername}/myrepo.git

Also remember if your password has '@' symbol use '%40' instead.

If you want to still go with private key approach, refer this question, How to access GIT repo with my private key from Dockerfile

Ravindu Nirmal Fernando
  • 4,272
  • 4
  • 18
  • 29
  • Cloning into 'myrepo'... fatal: could not read Username for 'https://github.com': No such device or address –  Nov 13 '17 at 09:59
  • Does myrepo git repository really exists? I used it as an example for the answer since you have added it with your question – Ravindu Nirmal Fernando Nov 13 '17 at 10:01
  • The actual repo name is different. Just for the example in this post I used myrepo. But, in terminal I am able to clone with SSh key. –  Nov 13 '17 at 10:04
  • I updated the answer. See whether it works. - NB - With this approach your username and password will be shared with your dockerfile as well. Read the answer given on the link I have submitted on the answer – Ravindu Nirmal Fernando Nov 13 '17 at 10:09