I have the following docker-compose.yml
file:
# some other services here
......
......
#############################
# Setup PostgreSQL container
#############################
service-postgres:
image: postgres:10-alpine
container_name: service-postgres-server
volumes:
- ./data/postgres:/var/lib/postgresql
- ./docker/initdb:/docker-entrypoint-initdb.d
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=root
- POSTGRES_DB=db_name
Each time I try to rebuild the containers running force-recreate I lose my database schema and data:
docker-compose up -d --force-recreate --build
But when I look under data/postgres
I found that files and settings are there:
-$ ls data/postgres
PG_VERSION pg_commit_ts pg_ident.conf pg_notify pg_snapshots pg_subtrans pg_wal postgresql.conf
base pg_dynshmem pg_logical pg_replslot pg_stat pg_tblspc pg_xact postmaster.opts
global pg_hba.conf pg_multixact pg_serial pg_stat_tmp pg_twophase postgresql.auto.conf postmaster.pid
How can I solve the issue and persist my database schema and data each time I need to rebuild the system.