【发布时间】: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
【问题讨论】: