嗨!
我有点卡在 docker-compose 中,因为我需要将我的 SSH 私钥传递到我的 docker-compose.yml
中声明的 Dockerfile
,如下所示:
docker-compose.yml
version: '3.7'
services:
worker:
build: .
args:
- SSH_PRIVATE_KEY
Dockerfile
ARG SSH_PRIVATE_KEY
RUN mkdir /root/.ssh/ && \
echo "${SSH_PRIVATE_KEY}" > /root/.ssh/id_rsa && \
chmod 600 /root/.ssh/id_rsa
使用 docker 本身,这很容易,因为我只需要运行以下命令:
docker build . --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)"
但是在 docker-compose 中... docker-compose 中 ARGS
配置的问题如描述in another question是我不能让 docker-compose.yml
文件中的私钥。
我需要让 docker-compose 访问 ~/.ssh/id_rsa
中的 key :关于如何执行它的任何线索?
谢谢!
最佳答案
docs on args指出:
You can omit the value when specifying a build argument, in which case its value at build time is the value in the environment where Compose is running.
在您的情况下,您可能希望使用以下命令构建 worker
服务:
SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" docker-compose build
顺便说一下,你的 docker-compose.yml
是错误的(缺少 context
),应该是:
version: '3.7'
services:
worker:
build:
context: .
args:
- SSH_PRIVATE_KEY
关于docker - 使用 docker-compose(SSH 私钥)将参数从文件传递给 Dockerfile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59802944/