gpt4 book ai didi

Docker-compose - 设置不是文字的环境变量

转载 作者:行者123 更新时间:2023-12-01 12:04:53 25 4
gpt4 key购买 nike

我已经在 Docker 容器中设置了 Jenkins,我正在尝试使用该服务器访问我的私有(private) Bitbucket 存储库。我需要将我的 SSH key 复制到该容器中,以便 Bitbucket 识别它,然后我可以让我的 Jenkins 服务器访问该存储库。

我的 docker-compose.yml 文件中有以下内容:

services:
jenkins:
build: .
volumes:
- jenkins-data:/var/jenkins_home
environment:
- SSH_PRIVATE_KEY=$(cat ~/.ssh/id_rsa)
ports:
- "8080:8080"
- "50000:50000"

volumes:
jenkins-data:

但是, echo $SSH_PRIVATE_KEY/.ssh/id_rsa从字面上看,而不是存储在里面的值。我听说在 Dockerfile 中执行此操作的问题在于,它仍然可以在将被推送的图像的一层中查看。

我的问题是如何设置 SSH_PRIVATE_KEY 的值我的文件内容的值(value)?

我相信这可能是 How to set environment variable into docker container using docker-compose 的副本但是,该解决方案似乎对我没有任何改变。

最佳答案

您可以在运行 compose 的 shell 中创建一个环境变量:

export SSH_PRIVATE_KEY=$(cat ~/.ssh/id_rsa)

然后在您的撰写中使用它,例如:
services:
jenkins:
build: .
volumes:
- jenkins-data:/var/jenkins_home
environment:
- SSH_PRIVATE_KEY
ports:
- "8080:8080"
- "50000:50000"

它应该从 docs 中指定的 shell 环境中为容器获取环境变量的值。 :

The value of the variable in the container is taken from the value for the same variable in the shell in which Compose is run.

关于Docker-compose - 设置不是文字的环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58622131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com