我正在尝试使用Docker构建一个镜像,导入存储在私有GitHub仓库中的npm包:
然后,运行
"mypackage": "git@github.com:myaccount/myrepo.git#v0.0.2"
。由于我拥有SSH访问权限,因此在本地可以正常工作,但是显然我的Docker容器没有这个权限。我按照以下指南实施了一些启用ssh转发的方法18.09:
https://medium.com/@tonistiigi/build-secrets-and-ssh-forwarding-in-docker-18-09-ae8161d066
使用以下 Docker 文件:# syntax=docker/dockerfile:experimental
FROM alpine
# Install ssh client and git
RUN apk add --no-cache openssh-client git
# Download public key for github.com
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
# Clone private repository
RUN --mount=type=ssh npm install
然后,运行
docker build --ssh default .
失败,并显示以下错误:#13 1.309 npm ERR! Host key verification failed.
#13 1.309 npm ERR! fatal: Could not read from remote repository.
#13 1.309 npm ERR!
#13 1.309 npm ERR! Please make sure you have the correct access rights
#13 1.309 npm ERR! and the repository exists.
#13 1.310 npm ERR!
#13 1.310 npm ERR! exited with error code: 128
我严格按照这份文档操作,但是一直没有成功。我是否漏掉了什么?我在OSX上操作,但是在Travis环境中也遇到了同样的错误。求助!
ssh-agent
或者只是使用默认的.ssh/id_rsa
密钥? - kichik--ssh
标志将连接从构建器转发到ssh-agent
。它不会共享您存放密钥的.ssh
文件夹。您需要运行ssh-agent
。 - kichikdocker build --ssh default
之前运行ssh-agent
即可。默认设置应该匹配。 - kichik