Answers: <p>Migrating data directory between major db version can be problematic.</p>
  
  <p>I can suggest to create and restore db dump.
  You can upgrade postgresql db container as follow:</p>
  
  <ol>
  <li>Backup database  </li>
  <li>Shutdown postgres 11 container </li>
  <li>Run new postgres 12 container </li>
  <li>Restore backup</li>
  </ol>
  
  <p>or single line command:</p>
  
  <pre><code>docker exec postgres-11-container pg_dumpall -U postgres | docker exec -i postgres-12-container psql -U postgres
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2019-12-17T08:30:48.867Z
Answers: 2019-12-17T08:30:48.867Z
Answers: Evgeny Anikiev
Body: <p>I'm new to this community, so feel free to tell me if this is a dup or belongs in another SE.</p>
  
  <p>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?</p>
  
  <p>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?</p>
  
Tags: <docker>
Title: Updating software in a docker container
UserDisplayName: Greg Schmit
ThreadText: # Updating software in a docker container
  
  (Asked by: username_0 on 2019-12-15)
  
  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?
  
  **Tags:** docker
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-12-17. Score: 4 | Accepted answer
  
  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
  
  ```
  
  
  ---
  
  