aph*_*ph5 6 docker docker-compose
我不知道如何将外部机密传递给docker-compose产生的服务。我执行以下操作:
我创造新的秘密
printf "some secret value goes here" | docker secret create wallet_password -
Run Code Online (Sandbox Code Playgroud)
我的docker-compose.yml:
version: "3.4"
services:
test:
image: alpine
command: 'cat /run/secrets/wallet_password'
secrets:
- wallet_password
secrets:
wallet_password:
external: true
Run Code Online (Sandbox Code Playgroud)
然后我运行:
docker-compose -f services/debug/docker-compose.yml up -d --build
Run Code Online (Sandbox Code Playgroud)
和
docker-compose -f services/debug/docker-compose.yml up
Run Code Online (Sandbox Code Playgroud)
我得到以下回应:
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
Run Code Online (Sandbox Code Playgroud)
Sooo ....有什么办法可以将外部机密传递给docker-compose生成的容器?
你需要运行一个集群。事情是这样的:
创建一个群体:
docker swarm init
创建您的秘密(根据需要创建多个):
docker secret create <secret_name> <secret_content>
使用以下命令检查所有可用的机密:
docker secret ls
现在,使用 docker-compose 作为服务的先驱:
docker stack deploy --compose-file <path_to_compose> <service_name>
请注意,您将在位于 的纯文本文件中找到您的秘密/run/secrets/<secret_name>。
不。
外部机密不适用于docker-compose创建的容器。
错误消息将其总结得很好。机密是群组模式功能,机密存储在群组管理器引擎内部。该管理员不会将这些秘密公开给外部启动的容器。只有具有机密信息的群集服务才能运行加载了机密信息的容器。
您可以在群体模式下运行服务以提取秘密,因为它只是容器内的一个文件,容器内的应用程序可以简单地cat取出文件内容。您还可以通过将文件作为卷安装在密钥所在的位置,从而在以compose开头的容器中复制密钥的功能。为此,您希望有一个单独的撰写文件,因为卷装入和秘密装入会相互冲突。
| 归档时间: |
|
| 查看次数: |
2189 次 |
| 最近记录: |