Postgresql 将数据和配置装载到postgres docker映像
我尝试使用Postgresql 将数据和配置装载到postgres docker映像,postgresql,docker,docker-compose,Postgresql,Docker,Docker Compose,我尝试使用docker compose将特定的数据文件夹和postgresql.conf装载到postgres映像中 这是我的docker-compose.yml示例: postgres: 图片:博士后:11 卷数: -./data/pg:/var/lib/postgresql/data#这是我的特定数据文件夹 -./postgresql.conf:/var/lib/postgresql/data/postgresql.conf#这里是我的自定义pg conf 但我在启动时发现错误: post
docker compose
将特定的数据文件夹和postgresql.conf装载到postgres映像中
这是我的docker-compose.yml示例:
postgres:
图片:博士后:11
卷数:
-./data/pg:/var/lib/postgresql/data#这是我的特定数据文件夹
-./postgresql.conf:/var/lib/postgresql/data/postgresql.conf#这里是我的自定义pg conf
但我在启动时发现错误:
postgres_1 | initdb: directory "/var/lib/postgresql/data" exists but is not empty
postgres_1 | If you want to create a new database system, either remove or empty
postgres_1 | the directory "/var/lib/postgresql/data" or run initdb
postgres_1 | with an argument other than "/var/lib/postgresql/data".
我猜我的第二卷(
/var/lib/postgresql/data/postgresql.conf
)与第一卷(/var/lib/postgresql/data
)冲突,因为如果我对第二卷进行注释,它可以正常工作。但是我不知道如何正确地执行这些操作,我希望能够同时装载(数据和conf)要做到这一点,您需要将postgresql.conf复制到另一个位置,然后指示postgres从新位置使用conf文件
大概是这样的:
version: "3.2"
services:
postgres:
image: postgres
volumes:
- ./data/pg:/var/lib/postgresql/data
- ./postgresql.conf:/etc/postgres/my.conf
command: "-c 'config_file=/etc/postgres/my.conf'"
跟在后面怎么样?在该页面上搜索“数据库配置”,注意数据目录外的绑定装载目标以及启动postgres的自定义选项-c
。