Postgresql 将docker postgres卷装入ubuntu现有postgres数据
我的ubuntu 18.04在本地安装了postgresql。我想将现有数据装载到docker 下面是我的Postgresql 将docker postgres卷装入ubuntu现有postgres数据,postgresql,docker,docker-compose,Postgresql,Docker,Docker Compose,我的ubuntu 18.04在本地安装了postgresql。我想将现有数据装载到docker 下面是我的docker compose.yml version: '3' services: db: image: postgres:10-alpine restart: always environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres ports:
docker compose.yml
version: '3'
services:
db:
image: postgres:10-alpine
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "15432:5432"
volumes:
- /etc/postgresql/10/main:/var/lib/postgresql/data
我没有在Ubuntu中更改默认的postgres 10配置。默认情况下,我认为配置位于/etc/postgresql/10/main
中,数据位于/var/lib/postgresql/10/main
中
如果我设定
volumes:
- /var/lib/postgresql/10/main:/var/lib/postgresql/data
它警告说
db_1 | postgres: could not access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory
db_1 | initdb: directory "/var/lib/postgresql/data" exists but is not empty
db_1 | If you want to create a new database system, either remove or empty
db_1 | the directory "/var/lib/postgresql/data" or run initdb
db_1 | with an argument other than "/var/lib/postgresql/data".
如果我换成
volumes:
- /etc/postgresql/10/main:/var/lib/postgresql/data
它警告说
db_1 | postgres: could not access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory
db_1 | initdb: directory "/var/lib/postgresql/data" exists but is not empty
db_1 | If you want to create a new database system, either remove or empty
db_1 | the directory "/var/lib/postgresql/data" or run initdb
db_1 | with an argument other than "/var/lib/postgresql/data".
如何在不创建新的本地docker卷的情况下解决此问题通过
docker volume create pgdata
您应该能够将两者指定到同一目录中:
volumes:
- "/var/lib/postgresql/10/main:/var/lib/postgresql/data"
- "/etc/postgresql/10/main/postgresql.conf:/var/lib/postgresql/data/postgresql.conf"