Ali4356
Ali4356

Reputation: 1437

Data is not deleted after docker container and volume is deleted

I have a Docker Compose setup which is supposed to just create a database using a volume I created earlier. If I delete everything and start fresh (image, container, volume) I will see in the logs that database x can't be found.

Where is docker getting this data? How do I make sure whenever I fire up a new Docker container it gets the data from the volume I set up and not from some other files?

version: "3"
services:
  postgresql:
    image: postgres:9.6
    restart: always
    container_name: "pgc"
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=test
    ports:
     - "5432:5432"
    volumes:
     - pgvol:/var/lib/postgresql/data
volumes:
    pgvol:
     external: true

Upvotes: 1

Views: 2243

Answers (1)

pszaba
pszaba

Reputation: 1064

Not sure if you want to create volume manually at all. If you use only

volumes:
    pgvol:

docker will create volumes for you and it will reuse it.

Otherise, if you want to create manually, make sure the volume exists with the desired name

docker volume ls

which is pgvol in your case, to create

docker volume create pgvol

Upvotes: 2

Related Questions