I decided to run Kanboard, an open source project management application, in a rootless Podman pod as a small weekend project. The pod consists of three containers, an infra-container, a kanboard-container, and a postgresql-container. That deployment went well, but eventually, the image I used for the postgresql-container became deprecated, meaning it was no longer receiving updates. It was time to move to a different image, but that meant migrating a database between containers. It sounds intimidating, but the process is actually straightforward. Here's how to do it.

Migrate to an upgraded PostgreSQL

The process for migrating a database in containers is mostly the same as it is for any other database, but with an additional step to manage containers. Here's an outline of the steps I took:

  1. Back up the current database.
  2. Stop and remove the container.
  3. Delete the directory and files of the old PostgreSQL version from the Podman volume.
  4. Move the SQL dump file to the Podman volume.
  5. Start the pod with the rhel8/postgresql-13 container.
  6. Restore the database.

[ Download the Bash shell scripting cheat sheet. ]

Here are the steps broken down.

First, back up the database:

$ podman exec -t [container name] \
/usr/bin/pg_dump [database name] > dump.sql

Next, empty the Podman volume of the database:

$ podman volume inspect [volume name]
$ sudo rm -rf \
~/.local/share/containers/storage/volumes/[volume name]/_data/*

Now move the database dump to the Podman volume:

$ mv dump.sql \
~/.local/share/containers/storage/volumes/[volume name>]/_data/

Note: be sure to start the postgresql-cotainer using the new container image rhel8/postgresql-13:

$ podman run -d --pod [pod name] --name [container name] \
-e POSTGRESQL_USER=root \
-e POSTGRESQL_PASSWORD=SecretPassword \
-e POSTGRESQL_DATABASE=[database name] \
-v [volume name]:/var/lib/pgsql/data:Z rhel8/postgresql-13

And finally, restore the database to the container:

$ podman exec -it [container name] bash
$ psql -U [user name] -d [database name] \
< /var/lib/pgsql/data/dump.sql

Give it a try

Migrating to a new database release in containers is not difficult when you know the steps. I also think you can apply these procedures to other databases that run in containers.

Haven't started your container journey yet? Well, you might begin with Alexon Oliveira's article on Podman scripting.


執筆者紹介

Jörg has been a Sysadmin for over ten years now. His fields of operation include Virtualization (VMware), Linux System Administration and Automation (RHEL), Firewalling (Forcepoint), and Loadbalancing (F5). He is a member of the Red Hat Accelerators Community and author of his personal blog at https://www.my-it-brain.de.

UI_Icon-Red_Hat-Close-A-Black-RGB

チャンネル別に見る

automation icon

自動化

テクノロジー、チームおよび環境に関する IT 自動化の最新情報

AI icon

AI (人工知能)

お客様が AI ワークロードをどこでも自由に実行することを可能にするプラットフォームについてのアップデート

open hybrid cloud icon

オープン・ハイブリッドクラウド

ハイブリッドクラウドで柔軟に未来を築く方法をご確認ください。

security icon

セキュリティ

環境やテクノロジー全体に及ぶリスクを軽減する方法に関する最新情報

edge icon

エッジコンピューティング

エッジでの運用を単純化するプラットフォームのアップデート

Infrastructure icon

インフラストラクチャ

世界有数のエンタープライズ向け Linux プラットフォームの最新情報

application development icon

アプリケーション

アプリケーションの最も困難な課題に対する Red Hat ソリューションの詳細

Virtualization icon

仮想化

オンプレミスまたは複数クラウドでのワークロードに対応するエンタープライズ仮想化の将来についてご覧ください