Ubuntu 26.04

Podman : Use External Storage2026/05/07

 

When a Container is removed, data in it are also lost, so it's necessary to use external storage on Containers if you'd like to save your data on Containers.

[1] It's possible to mount a directory on Docker Host into Containers.
# create a directory for containers data

root@dlp:~#
mkdir /var/lib/containers/disk01

root@dlp:~#
echo "persistent storage" >> /var/lib/containers/disk01/testfile.txt

# run a Container with mounting the directory above on [/mnt]

root@dlp:~#
podman run -it -v /var/lib/containers/disk01:/mnt ubuntu /bin/bash
root@e40f9e825ddf:/#
df -hT /mnt

Filesystem                        Type  Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv ext4   77G  7.7G   65G  11% /mnt

root@e40f9e825ddf:/#
cat /mnt/testfile.txt

persistent storage
[2] It's also possible to configure external storage by Podman Data Volume command.
# create [volume01] volume

root@dlp:~#
podman volume create volume01

volume01
# display volume list

root@dlp:~#
podman volume ls

DRIVER      VOLUME NAME
local       volume01

# display details of [volume01]

root@dlp:~#
podman volume inspect volume01

[
     {
          "Name": "volume01",
          "Driver": "local",
          "Mountpoint": "/var/lib/containers/storage/volumes/volume01/_data",
          "CreatedAt": "2026-05-06T07:43:29.842962758Z",
          "Labels": {},
          "Scope": "local",
          "Options": {},
          "MountCount": 0,
          "NeedsCopyUp": true,
          "NeedsChown": true,
          "LockNumber": 9
     }
]

# run a container with mounting [volume01] to [/mnt] on container

root@dlp:~#
podman run -it -v volume01:/mnt ubuntu
root@6d7abc288bfd:/#
df -hT /mnt

Filesystem                        Type  Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv ext4   77G  7.7G   65G  11% /mnt

root@6d7abc288bfd:/#
echo "Podman Volume test" > /mnt/testfile.txt

root@6d7abc288bfd:/#
exit
root@dlp:~#
cat /var/lib/containers/storage/volumes/volume01/_data/testfile.txt

Podman Volume test
# possible to mount from other containers

root@dlp:~#
podman run -v volume01:/var/volume01 ubuntu cat /var/volume01/testfile.txt

Podman Volume test
# to remove volumes, do like follows

root@dlp:~#
podman volume rm volume01

Error: volume volume01 is being used by the following container(s): 6d7abc288bfd9c9d587183180a8444690f8d79dc733cb9115a7c8f359c3741a5, 8983b0cb34727893418bc3496da410bcf48f857520d0f329d51fbbcdb84776cb: volume is being used

# if some containers are using the volume you'd like to remove like above,
# it needs to remove target containers before removing a volume

root@dlp:~#
podman rm 6d7abc288bfd9c9d587183180a8444690f8d79dc733cb9115a7c8f359c3741a5

root@dlp:~#
podman rm 8983b0cb34727893418bc3496da410bcf48f857520d0f329d51fbbcdb84776cb
root@dlp:~#
podman volume rm volume01

volume01
Matched Content