Hi Vishal,
I’m still learning Docker too. I verified that you are correct. After I did a “docker-compose down”, I no longer had my data.
The response by Michael above provided the correct solution. I updated my docker compose file to be:
version: '2'
# docker volume create --name data -d local
services:
postgres:
restart: always
container_name: postgres_db
image: postgres:latest
#tty: true
ports:
- "5432:5432"
volumes:
- data:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: docker
POSTGRES_DB: db
#PGDATA: /tmp
volumes:
data:
external: true
After, creating the “data” volume, I did a docker-compose. Everything initialized fine (no errors). I then created a database and loaded it with data. I then did a docker-compose down
followed by a docker-compose up
and the data was still there.
The thing that I am unsure of is where on the disk is this data stored. docker volume inspect
does not provide any meaningful information.