When I run docker-compose down without -v or --volumes, why my data is lost? Does Docker deletes my volume?
When I inspect with docker volume inspect pgdata, it shows up always the current timestamp, looks like it is always recreated each time.
But when I just stopped the postgres container with docker stop <container_id> and re-run the container, the data is still there. Here is my docker-compose
version: '3.7'
services:
app:
container_name: bsf-quiz-app
image: sapkotasuren/bsf-quiz
ports:
- "443:8443"
depends_on:
- postgresqldb
postgresqldb:
image: postgres:latest
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=password
- POSTGRES_USER=postgres
- POSTGRES_DB=bsfQuiz
volumes:
pgdata:
I tried to do it on bind mount way, I see a lot of data being created but still the same issue could not find the record which I have created before on the database, after docker-compose down and up.
I also tried to create named volume using docker command:
docker create volume postgres, and mention it on my yaml file and set external to true. still the same issue!
my yaml file:
version: '3.9'
services:
app:
container_name: bsf-quiz-app
image: sapkotasuren/bsf-quiz
ports:
- "443:8443"
depends_on:
- postgresqldb
postgresqldb:
container_name: postgres
image: postgres:latest
volumes:
- postgres:/var/lib/postgresql/data
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=password
- POSTGRES_USER=postgres
- POSTGRES_DB=bsfQuiz
volumes:
postgres:
external: true
According to the documentation, docker compose down will not delete any volume unless the -v option is used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With