0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.