【发布时间】:2020-08-06 12:14:36
【问题描述】:
我正在尝试将 SSH 密钥传递到 Dockerfile 中,以便我可以从 Git 中提取私有存储库。
当我在命令行上使用它时它可以工作
export SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)"
docker build --build-arg SSH_PRIVATE_KEY --tag image:latest .
下面是我的 Dockerfile 的 sn-p
ARG SSH_PRIVATE_KEY
RUN apt-get update && apt-get install -y git && apt-get install -y nano && \
apt-get update && apt-get install -y python3.7 python3-pip python3.7-dev && \
rm -rf /var/lib/apt/lists/*
RUN mkdir -p ~/.ssh && umask 0077 && echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa \
&& git config --global url."git@github.com:".insteadOf https://github.com/ \
&& ssh-keyscan github.com >> ~/.ssh/known_hosts
但是,当我尝试从这样的 makefile 运行它时
SSH_PRIVATE_KEY=$(shell cat ~/.ssh/id_rsa)
build-image:
docker build --build-arg SSH_PRIVATE_KEY="${SSH_PRIVATE_KEY}" --tag image:latest -f ./docker/Dockerfile .
我得到了错误
加载密钥“/root/.ssh/id_rsa”:格式无效
我做错了什么吗?
谢谢!
【问题讨论】:
-
我假设您知道为什么会收到
invalid format。我只是尝试复制并使用直接docker build得到invalid format。 -
我错过了 dockerfile 中 SSH var 周围的一些引号,示例现在应该与直接 docker build 一起使用
标签: docker github makefile dockerfile ssh-keys