Persist Postgres data using Docker volumes
mainBy default, data in a container is ephemeral and lost when the container is deleted. To persist your database data on your local machine, use the volumes tag to map a local directory to the container's data path /var/lib/postgresql/data/.
Use the ${PWD} variable to reference your current working directory.
services:
database:
# ...
volumes:
- ${PWD}/db-data/:/var/lib/postgresql/data/