gpt4 book ai didi

docker - 使用 docker-compose 时如何读取外部 secret

转载 作者:行者123 更新时间:2023-12-02 04:09:46 78 4
gpt4 key购买 nike

我想知道如何将外部 secret 传递到 docker-compose 生成的服务中。我执行以下操作:

我创建新的 secret

printf "some secret value goes here" | docker secret create wallet_password -

我的 docker-compose.yml:

version: "3.4"
services:
test:
image: alpine
command: 'cat /run/secrets/wallet_password'
secrets:
- wallet_password

secrets:
wallet_password:
external: true

然后我运行:

docker-compose -f services/debug/docker-compose.yml up -d --build

docker-compose -f services/debug/docker-compose.yml up

我收到以下回复:

WARNING: Service "test" uses secret "wallet_password" which is external. External secrets are not available to containers created by docker-compose.
WARNING: The Docker Engine you're using is running in swarm mode.

Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.

To deploy your application across the swarm, use `docker stack deploy`.

Starting debug_test_1 ...
Starting debug_test_1 ... done
Attaching to debug_test_1
test_1 | cat: can't open '/run/secrets/wallet_password': No such file or directory

Sooo....有什么方法可以将外部 secret 传递到 docker-compose 生成的容器中吗?

最佳答案

不。

External secrets are not available to containers created by docker-compose.

错误消息很好地总结了这一点。 secret 是群体模式功能, secret 存储在群体管理器引擎内部。该管理器不会将这些 secret 暴露给外部启动的容器。只有具有 secret 的集群服务才能运行加载了 secret 的容器。

您可以在群体模式下运行一个服务来提取 secret ,因为它只是容器内的一个文件,容器内的应用程序可以简单地 cat 提取文件内容。您还可以通过将文件作为卷安装到 key 位置来复制以 compose 启动的容器中 key 的功能。为此,您需要一个单独的撰写文件,因为卷安装和 secret 安装会相互冲突。

关于docker - 使用 docker-compose 时如何读取外部 secret ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49955542/

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