我正在尝试在MacOS上使用--ssh default
构建Docker镜像,但无法正常工作。相同的构建在Linux上可以。
//Dockerfile
#syntax=docker/dockerfile:experimental
FROM node:16
WORKDIR /app
RUN chown -R node.node /app
RUN mkdir ~/.ssh/ && ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
RUN --mount=type=ssh git clone git+ssh://git@github.com/account_name/repo.git
CMD tail -f /dev/null
当我运行时
docker build --ssh default -t my_image .
我收到了错误信息:
git@github.com: Permission denied (publickey)
fatal: Could not read from remote repository
我在本地机器上的 ~/.ssh/id_rsa
中有我的 ssh 密钥,并且它在 Docker 之外可以使用。
如果我在 Dockerfile 中尝试运行:
RUN --mount=type=ssh cat ~/.ssh/id_rsa
我遇到了错误:
cat: /root/.ssh/id_rsa No such file or directory