Updating software in a docker container 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?
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:


Backup database  
Shutdown postgres 11 container 
Run new postgres 12 container 
Restore backup


or single line command:

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