当Build试图克隆私人仓库时,我遇到了这个错误:
克隆到“。” ...主机密钥验证失败。 致命:无法从远程存储库读取。请确保您具有正确的访问权限,并且存储库存在。
这是构建命令:
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
答案 0 :(得分:3)
问题是您为root用户设置了ssh环境,然后切换到用户容器(其中不存在ssh配置),然后尝试访问github。在〜container / .ssh中生成ssh配置。