After reading
How to persist data in a dockerized postgres database using volumes
I know mount a volume to local host folder, is a good way to prevent data loss, in case fatal happens in docker process.
I'm using Windows as host and Linux based docker image. Windows is having problem to mount postgres data (Linux based docker image) to Windows host directory - Mount Postgres data to Windows host directory
Later, I discover another technique
postgres:
build:
context: ./postgres
dockerfile: Dockerfile
restart: always
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data: {}
I can use a non external volume (I have no idea what is that yet)
After implement such, I try to perform
docker-compose down
docker-compose up
The data is still there.
May I know,
- Is this still a good way to persist data in dockerized postgres?
- Where exactly data is being stored? Is it some hidden directory in host machine?