Reputation:
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 [email protected]: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 [email protected]: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
Upvotes: 0
Views: 3350
Reputation: 4822
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
Upvotes: 1