dockerfile生成时主机密钥验证失败

dockerfile生成时主机密钥验证失败,docker,github,dockerfile,Docker,Github,Dockerfile,我使用ssh-keygen创建了一个ssh密钥,并将id-rsa.pub内容添加到我的github>settings>ssh&GPG密钥中。 我可以用git clone从终端克隆回购协议git@github:myname/myrepo.git 但在构建docker文件时,同样会出现以下错误 Cloning into 'Project-Jenkins'... Host key verification failed. fatal: Could not read from remote reposi

我使用
ssh-keygen
创建了一个ssh密钥,并将id-rsa.pub内容添加到我的
github>settings>ssh&GPG密钥中。
我可以用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
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
这里出了什么问题

这是我的文件

RUN git clone git@github.com:myname/myrepo.git
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

您使用的语法最终使用SSH进行克隆,在docker容器中,您的github私钥不可用,这会导致出现错误。所以试着用

RUN git clone https://{myusername}:{mypassword}@github.com/{myusername}/myrepo.git
还要记住,如果您的密码有“@”符号,请改用“%40”


如果您仍然希望使用私钥方法,请参考此问题,

您可以添加完整的Dockerfile,还是只包含您拥有的RUN git clone命令mentioned@RavinduFernando我已将dockerfile添加到“myrepo”中。。。致命:无法读取“”的用户名:没有此类设备或地址myrepo git存储库是否确实存在?我用它作为回答的一个例子,因为你已经把它和你的问题一起添加了。实际的回购协议名称是不同的。就拿这篇文章中的例子来说,我使用了myrepo。但是,在终端中,我可以使用SSh密钥进行克隆。我更新了答案。看看它是否有效注意-通过这种方法,您的用户名和密码也将与dockerfile共享。阅读我提交的答案链接上给出的答案