Podman : 外部ストレージを利用する2026/01/09 |
|
コンテナーが破棄されると当然コンテナー内部のデータも消失するため、コンテナーで作成したデータを永続化するには、外部ストレージを利用する必要があります。 |
|
| [1] | ホスト側の任意のディレクトリーをコンテナーにマウントして利用することができます。 |
|
root@dlp:~ # podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/freebsd-nginx latest 3cd54285ea87 5 minutes ago 1.02 GB localhost/freebsd-httpd latest dbf5f8b9e7e2 14 minutes ago 1.19 GB localhost/freebsd-base latest afb96df72092 45 minutes ago 902 MB quay.io/centos/centos stream10 e9ac565bc256 2 days ago 316 MB docker.io/library/ubuntu latest c3a134f2ace4 2 months ago 80.6 MB # 任意のデータ保管用ディレクトリー作成 root@dlp:~ # mkdir /var/lib/containers/disk01 root@dlp:~ # echo "persistent storage" >> /var/lib/containers/disk01/testfile.txt # 作成したディレクトリーをコンテナーの [/mnt] にマウントして起動 root@dlp:~ # podman run -it -v /var/lib/containers/disk01:/mnt freebsd-base /bin/sh
df -hT /mnt Filesystem Type Size Used Avail Capacity Mounted on /var/lib/containers/disk01 nullfs 73G 1.6G 72G 2% /mnt# cat /mnt/testfile.txt persistent storage |
| [2] | データボリュームを作成して利用することもできます。 |
|
# [volume01] ボリューム作成 root@dlp:~ # podman volume create volume01 volume01 # ボリューム一覧表示 root@dlp:~ # podman volume ls DRIVER VOLUME NAME local volume01 # [volume01] の詳細表示 root@dlp:~ # podman volume inspect volume01
[
{
"Name": "volume01",
"Driver": "local",
"Mountpoint": "/var/db/containers/storage/volumes/volume01/_data",
"CreatedAt": "2026-01-09T09:30:55.756234908+09:00",
"Labels": {},
"Scope": "local",
"Options": {},
"MountCount": 0,
"NeedsCopyUp": true,
"NeedsChown": true,
"LockNumber": 12
}
]
# [volume01] を コンテナー上の [/mnt] にマウントして起動 root@dlp:~ # podman run -it -v volume01:/mnt freebsd-base /bin/sh
df -hT /mnt Filesystem Type Size Used Avail Capacity Mounted on /var/db/containers/storage/volumes/volume01/_data nullfs 73G 1.6G 72G 2% /mnt
#
echo "Podman Volume test" > /mnt/testfile.txt # exit
root@dlp:~ #
cat /var/db/containers/storage/volumes/volume01/_data/testfile.txt Podman Volume test # 別コンテナーからも利用可 root@dlp:~ # podman run -v volume01:/var/volume01 freebsd-base /bin/cat /var/volume01/testfile.txt Podman Volume test # ボリュームを削除する場合は以下 root@dlp:~ # podman volume rm volume01 Error: volume volume01 is being used by the following container(s): 083b1204bd5edefe2288e7d4ad5b4253cc28fb39ea517270cf332e52ab6e3aba, 7b68ccac1314990ee6994e9b95800d5a1439b5d4f26bba24e3548beecbe9a20a: volume is being used # 上記のようにコンテナーがボリュームを使用中の場合は削除不可のため # ボリュームを削除したい場合は先にコンテナーを削除 root@dlp:~ # podman rm 083b1204bd5edefe2288e7d4ad5b4253cc28fb39ea517270cf332e52ab6e3aba root@dlp:~ # podman rm 7b68ccac1314990ee6994e9b95800d5a1439b5d4f26bba24e3548beecbe9a20a
podman volume rm volume01 volume01 |
| Sponsored Link |
|
|