简体   繁体   中英

Postgres docker instance doesn't persist state after restart

I pulled and run the postgres official image from docker-hub. Everything works but the problem is when i stop and start the container all data is lost and instance returns to a clean state, while i'm expecting data to be persisted on the instance self storage.

i don't want to use external volumes in order to keep the instance self contained.

is this a configuration issue?

Yes: you need to use external volumes (either native Docker volumes or host directories), that's not really optional. Deleting and recreating containers is extremely routine (you need to do it to take a security patch in the database software or surrounding Linux distribution infrastructure if nothing else) and if you delete a container you lose all of the data that was in it.

A typical PostgreSQL invocation would look like

docker run \
  --name postgres \
  -d \
  -p 5432:5432 \
  -v $PWD/pgdata:/var/lib/postgresql/data \
  postgres:11

https://hub.docker.com/_/postgres/ lists out all of the environment variables and container filesystem paths that are interesting to a typical user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM