码头工人组成秘密无群 [英] docker-compose secrets without swarm
问题描述
我不想将docker secrets与swarm一起使用,我发现这样做是可行的.
基本上,docker只是将/run/secrets挂载在docker容器中,但是当我进入新建的docker容器并执行echo $POSTGRES_PASSWORD_FILE
时,我会得到秘密文件的路径.
I don't want to use docker secrets with swarm and I discovered that it's possible to do that.
Basically docker just mounts /run/secrets inside docker container, but when I enter the newly built docker container and do echo $POSTGRES_PASSWORD_FILE
I get the path to my secret file.
root@94a0f092eeb1:/# echo $POSTGRES_PASSWORD_FILE
/run/secrets/db_password
这是我的docker-compose.yml
文件
version: '3.1'
services:
postgres:
image: postgres:9.4
container_name: postgres
environment:
POSTGRES_USER: "db_user"
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
POSTGRES_DB: "my_db"
secrets:
- db_password
volumes:
- ./postgres:/var/lib/postgresql/data
expose:
- 5432
secrets:
db_password:
file: ./POSTGRES_PASSWORD.txt
我的密码设置正确吗/我的文件有问题吗?
Is my password set correctly/ Is there something wrong with my file?
推荐答案
好,所以我要做的就是删除
Ok, so all I had to do is to remove
volumes:
- ./postgres:/var/lib/postgresql/data
我将尝试找出解决方法,但从本质上讲,我回答了自己的问题.
I'll try to figure out how to fix it, but essentially I answered my own question.
这是docker-compose.yml
文件的工作示例,其中包含秘密而不使用docker swarm:
Here is a working example of docker-compose.yml
file with secrets without using docker swarm:
version: '3.1'
services:
postgres:
image: postgres:9.4
container_name: postgres
environment:
POSTGRES_USER: "db_user"
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
POSTGRES_DB: "my_db"
secrets:
- db_password
ports:
- "8888:5432"
secrets:
db_password:
file: ./POSTGRES_PASSWORD
这篇关于码头工人组成秘密无群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!