dockerfile构建时主机密钥验证失败

时间:2017-11-13 09:26:56

标签: docker github dockerfile

我使用ssh-keygen创建了一个ssh密钥,并将id-rsa.pub内容添加到我的github>settings>SSH & GPG keys。 我可以使用git clone git @github:myname / myrepo.git

从我的终端克隆回购

但是在构建docker文件时同样会出现以下错误。

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.

这就是我在dockerfile中添加命令的方法

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

这里出了什么问题?

这是我的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 个答案:

答案 0 :(得分:0)

您使用的语法最终使用SSH进行克隆,并且在docker容器内,您的github私钥不可用,这会导致您获得错误。所以请尝试使用,

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

另请记住,如果您的密码有'@'符号,请使用'%40'。

如果您仍想使用私钥方法,请参阅此问题How to access GIT repo with my private key from Dockerfile