1

I'm new to this community, so feel free to tell me if this is a dup or belongs in another SE.

I am new to docker, and it's a really cool concept, but I'm struggling with the idea of packaging an app that will be updated later. Suppose, for example, that I've packaged an app that uses a postgres database that I included in the same container. When I build a new image going from postgres 11 to postgres 12, I need to migrate the data directory. How is that normally handled with docker?

My example might be bad, because proper design would have the DB in another container, but suppose I want to upgrade that postgres image, does the new postgres image handle the migration automatically? Is there a common way to run a script when the image is upgraded?

1 Answer 1

4

Migrating data directory between major db version can be problematic.

I can suggest to create and restore db dump. You can upgrade postgresql db container as follow:

  1. Backup database
  2. Shutdown postgres 11 container
  3. Run new postgres 12 container
  4. Restore backup

or single line command:

docker exec postgres-11-container pg_dumpall -U postgres | docker exec -i postgres-12-container psql -U postgres

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.