问题原文
原帖链接 · André Fratelli · CC BY-SA 4.0
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?
已采纳解答
原帖链接 · OYPS · CC BY-SA 4.0
The docker volume driver is not persisting your data between restarts of services. You can use the local-persist driver ; I have used this several times for this use case.
When you already have the data somewhere you can create the volume before starting the services and copy your data to the specified directory. Postgres should pick up the database from there.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
