【问题标题】:Dockerfile - “Host key verification failed…” errorDockerfile - “主机密钥验证失败...”错误
【发布时间】:2020-12-16 20:08:01
【问题描述】:

当 Build 尝试克隆私有 repo 时出现此错误:

克隆到“.”...主机密钥验证失败。 致命:无法从远程存储库中读取。请确保您具有正确的访问权限并且存储库存在。

这是构建命令:

docker build --tag myimage --build-arg ssh_prv_key="$(cat ~/.ssh/id_rsa)" --build-arg ssh_pub_key="$(cat ~/.ssh/id_rsa.pub)" .

这里是 Dockerfile:

FROM tarampampam/node:13-alpine

ARG ssh_prv_key
ARG ssh_pub_key

RUN mkdir /root/.ssh/

RUN adduser "container" -D -h "/home/container"

RUN echo "$ssh_prv_key" > /root/.ssh/id_rsa && \
    echo "$ssh_pub_key" > /root/.ssh/id_rsa.pub && \
    chmod 600 /root/.ssh/id_rsa && \
    chmod 600 /root/.ssh/id_rsa.pub

RUN  echo "    IdentityFile ~/.ssh/id_rsa" >> /etc/ssh/ssh_config

RUN touch /root/.ssh/known_hosts
RUN echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
RUN ssh-keyscan -H github.com >> ~/.ssh/known_hosts

USER container
ENV  USER container
ENV  HOME /home/container

RUN cd /home/container && git clone git@github.com:myPrivateRepo .

RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -    && apt update     && apt -y upgrade     && apt -y install nodejs node-gyp     && apt -y install ffmpeg     && npm install discord.js node-opus opusscript     && npm install >


WORKDIR /home/container

我检查过,/root/.ssh/id_rsa 和 /root/.ssh/id_rsa.pub 里面都有好密钥。

我尝试了很多选项,例如 ssh-keygen -R github.com

【问题讨论】:

    标签: git docker


    【解决方案1】:

    问题是你为root用户设置了ssh环境,然后切换到用户容器(ssh配置不存在),然后尝试访问github。在 ~container/.ssh 中生成 ssh 配置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-27
      • 1970-01-01
      • 2021-12-25
      • 2013-02-16
      • 1970-01-01
      • 2020-07-15
      • 2018-10-04
      • 2020-10-30
      相关资源
      最近更新 更多