Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why docker-compose down deletes my volume? how to avoid this action done by 'down'. (Postgresql)

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:

Updated 20/01/2021

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
like image 776
Suren Avatar asked Jan 21 '26 11:01

Suren


1 Answers

According to the documentation, docker compose down will not delete any volume unless the -v option is used.

like image 139
stackoverflowed Avatar answered Jan 24 '26 10:01

stackoverflowed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!