Reputation: 6493
I have a docker-compose file that contains:
version: '3'
services:
postgres:
image: "postgres"
network_mode: "host"
volumes:
- "/run/postgresql:/run/postgresql:Z"
- "postgresData:/var/lib/postgresql/data"
volumes:
postgresData: {}
However when I run docker-compose down
and then docker-compose up
the postgres data is lost. From what I understand this is the intended default behavior however I want to change this so my postgres data is never reset. Or maybe I am misunderstanding what docker-compose down
is for. I see there is also the stop
and start
commands but it seems unclear if I can run docker-compose pull
without running down
.
How can I make sure that my postgres data is always persisted?
Upvotes: 1
Views: 1146
Reputation: 2741
If you remove the curly braces this should work Official doc
version: '3'
services:
postgres:
image: "postgres"
network_mode: "host"
volumes:
- postgresData:/var/lib/postgresql/data
volumes:
postgresData:
docker-compose up: offcial-doc up - Builds, (re)creates, starts, and attaches to containers for a service.
docker-compose start: offcial-doc start - Starts existing containers for a service.
docker-compose down:offcial-doc down - Stops containers and removes containers, networks by default, if you want to remove volumes use -v flag
docker-compose stop: offcial-doc stop
- Stops running containers without removing them. They can be started again with docker-compose start
Upvotes: 3