当 运行 git 将 AWS EC2 实例上的 dockerfile 克隆为主机和私有 git 存储库时出现主机验证失败错误

Host verification failed error when running git clone inside dockerfile on AWS EC2 instance as host and a private git repository

我正在使用 AWS ec2 实例作为私有 git 存储库。此实例还用于 运行 Dockerfile 和 docker 文件尝试从该私有存储库检出代码。我的基本设置是根据 https://alvinabad.wordpress.com/2013/03/23/how-to-specify-an-ssh-key-file-with-the-git-command/ 选项 2 完成的。但是,当我 运行 我的 docker 构建命令时:

$ sudo docker build -t "spring-petclinic" .

构建脚本在行处停止:

运行 /root/.ssh/git.sh -i /root/.ssh/.pem clone ec2-user@ec2-xx-xxx-xxx-xxx.compute- 1.amazonaws.com:/usr/local/git-repos/spring-petclinic.git

并出现以下错误:

"Cloning into 'spring-petclinic'... Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists."

我在 google 中搜索了类似设置的此类错误,但无法搜索到。

请帮忙!!!

谢谢

您看到的问题是它是第一次连接到未知主机,默认情况下 SSH 安全运行。如果您是 运行 交互命令,系统会提示您将密钥添加到 known_hosts 文件。

您可以将主机密钥添加到 known_hosts 文件(更好)或在 ssh 配置中将 StrictHostKeyChecking 设置为 no(更差)。