I have the following compose file, from this project:
version: "3"
volumes:
static-files:
driver: local
postgres:
driver: local
services:
db:
image: postgres:11.1
volumes:
- postgres:/var/lib/postgresql/data/pgdata
env_file:
- ./config/environment/development.env
expose:
- "5432"
webapp:
build:
context: webapp
volumes:
- ./webapp/covidoff:/srv/covidoff
- static-files:/srv/static-files
ports:
- "8000:8000"
- "80:8000"
depends_on:
- db
env_file:
- ./config/environment/development.env
As you can see, there are two services being launched: a PostgreSQL database db
and a Django webapp
. Everything is working well so far, except for one thing: every time I stop the db
container the data is lost.
Someone told me to try postgres:/var/lib/postgresql/data
instead of postgres:/var/lib/postgresql/data/pgdata
, but that didn't work either.
The problem is: this server is already live and with data. How can I solve the persistence problem and still keep the current data?
Some progress. A simple change made it so that the data persists after the container is stopped, I'm just not sure why. I replaced this:
PGDATA=pgdata
With this:
PGDATA=/var/lib/postgresql/data/pgdata
In my env
file. But why does this work?