Rocky Linux 10 Tutorial / Run rootless Podman with persistent data

Using rootless Podman on Rocky Linux 10 allows containers to run with regular user privileges. However, to safely maintain data when replacing containers, it's necessary to check the port exposure range, data stored on the host, user ID mapping, and SELinux context individually.

Checking rootless status in a regular user environment

Containers run by isolating an application's processes, file system, and network while sharing the host kernel. Rootless means running without root privileges on the host. Even if you appear as root inside the container, you are not the same as the host's root user.

The source lab environment was Rocky Linux 10.2, Podman 5.8.2, crun 1.30.1, with SELinux Enforcing, and the regular user lfstudent has a user and group ID (UID·GID) of 1000. The administrator installs the packages, but subsequent podman commands are executed in the login shell of that regular user. If switched to sudo podman, you would see a separate image store and containers owned by root, so mixing is avoided.

sudo dnf install podman
id
podman version
podman info --format '{{.Host.Security.Rootless}}'
podman info --format '{{.Store.GraphRoot}}'
grep "^$(id -un):" /etc/subuid /etc/subgid
podman unshare cat /proc/self/uid_map /proc/self/gid_map

The rootless query should return true, and this user's image storage was /home/lfstudent/.local/share/containers/storage. The subordinate ID setting provides a range to map additional UIDs and GIDs inside containers to the regular user. In this VM, lfstudent:524288:65536 is already registered, so it was not modified. If it does not exist or overlaps with another user's range, the administrator must check the entire allocation and configure it; do not add the example numbers as-is.

Rocky Linux rootless Podman documentation explains user mapping, local storage, and login session conditions. The source exercise used local XFS storage and with cgroups v2 managing process resources. Do not assume that a shared home directory or other session configurations are the same environment.

Image sources and actual digest logs

An image bundles the programs and initial files used to create a container; a registry distributes images. This example uses Docker Hub's docker.io/library/nginx image, maintained through the official NGINX Dockerfile repository . Use the fully qualified image name rather than a short name that omits its registry and repository.

LAB27="$HOME/lf-course27"
test ! -e "$LAB27" || { printf 'Inspect the existing lab directory and stop.\n' >&2; exit 1; }
podman ps -a
podman images
mkdir -m 0755 "$LAB27"
podman pull docker.io/library/nginx:stable-alpine
podman image inspect docker.io/library/nginx:stable-alpine --format '{{.Id}} {{.Digest}} {{.RepoDigests}} {{.Architecture}}'
podman image inspect docker.io/library/nginx:stable-alpine --format '{{index .RepoDigests 0}}' > "$LAB27/image.ref"
IMAGE27=$(cat "$LAB27/image.ref")

If the same practice directory or lf-course27-web container already exists, stop and check the existing state. test returns exit code 0 if the path does not exist, and 1 if it does, and does not output a separate message when normal. Subsequent commands are executed in the same regular user shell, and if newly logged in, LAB27 and IMAGE27 are reset from the record file.

stable-alpine is a tag whose content can change. In this amd64 image, Nginx was 1.30.6, and the recorded reference was docker.io/library/nginx@sha256:583b7f2fce1cdb8da5ad5c39ebd3c33b98b87d493190e548bdee1fa8c619c311. RepoDigests may include both multi-architecture indexes and platform image references, and the digest of this platform image was sha256:bb8f722b4be005fcd7827816a136ab779fd40185d85b5171be915cc7fc0575c7. Since these values refer to different targets, differing numbers are not immediately judged as corruption.

The later commands reuse the recorded image reference and pass --pull=never to use the local image. Pinning the digest is a way to clearly specify the target for this run, and it is not a function to automatically apply security updates. When updating the image, you must verify the new source·digest and the application behavior again. The podman pull documentation explains reference formats and download options.

Loopback port and read-only document directory

We will create a document directory on the host and use a bind mount to link it to the container's document path. The 127.0.0.1:18027:80 below connects the VM's own loopback port 18027 to port 80 of the container. Even if you are running the VM on Windows, the "host" here refers to the Rocky Linux VM running Podman.

ss -lnt 'sport = :18027'
mkdir -m 0755 "$LAB27/site"
printf 'LF27 persistent version A\n' > "$LAB27/site/index.html"
chmod 0644 "$LAB27/site/index.html"
podman run -d --name lf-course27-web --label lf.course=27 --pull=never -p 127.0.0.1:18027:80 -v "$LAB27/site:/usr/share/nginx/html:ro,Z" "$IMAGE27"
curl --retry 3 --retry-all-errors --retry-delay 1 --max-time 5 -fsS http://127.0.0.1:18027/
podman port lf-course27-web
podman logs --tail 15 lf-course27-web

Run when a port is available. The expected content is LF27 persistent version A, and port lookup is 80/tcp → 127.0.0.1:18027. A reset was observed on the first connection immediately after start, so curl is set to retry only a limited number of times. If repeated attempts fail, do not just wait; check actual startup in podman ps -a and the logs.

Omitting the host IP in -p 18027:80 may change the exposure scope. This time, since it is a local test, it was explicitly bound to the loopback, and no firewall or VM NAT rules were added. External exposure involves designing and verifying the actual receiving address, network path, and policy separately. Ports and mount options can be checked in the podman run official documentation .

Mount Options Meaning and Scope
ro Makes the mount read-only in the container. It is separate from the host owner modifying the original file.
Z Re-labels the original path with a non-shared SELinux context suitable for this container. Use only on newly created dedicated directories.
z Applies a context shared among multiple containers. First, determine if the necessary sharing scope is required.
U An option to recursively change the original ownership according to user mapping. It is not necessary for simple read-only practice, and the actual host file owner may be changed.

Applying :Z to the entire home or system directories can change the file context of other programs as well, so this example only links a new site path. If two independent containers apply :Z on the same path, the last context change may affect access to the previous container.

In the source comparison, when the first document was in the user_home_t state, using only :ro resulted in HTTP 403 and file access denial logs. When the same material was linked to :ro,Z, container_file_t and the dedicated category were applied, and it returned 200. General permissions were not changed to 0777, nor was SELinux disabled.

ls -Zd "$LAB27/site" "$LAB27/site/index.html"
podman exec lf-course27-web sh -c 'printf denied > /usr/share/nginx/html/blocked.txt'
printf 'LF27 persistent version B\n' > "$LAB27/site/index.html"
curl -fsS http://127.0.0.1:18027/

The write test is a deliberately failing command. A non-zero exit code is expected with Read-only file system, and blocked.txt should not be created. On the other hand, the original file modified on the host was immediately provided as LF27 persistent version B. A read-only mount restricts writes through that container mount. It does not guarantee permanent preservation or prevent host-side changes.

Recreate the container to check data preservation.

Let's distinguish between the writable file layers inside the container and the host bind mount. First, create an internal temporary file and record the current container ID along with the hash of the host data.

podman exec lf-course27-web sh -c 'printf ephemeral > /tmp/lf27-ephemeral'
podman inspect lf-course27-web --format '{{.Id}}'
sha256sum "$LAB27/site/index.html"
podman rm -f lf-course27-web
podman run -d --name lf-course27-web --label lf.course=27 --pull=never -p 127.0.0.1:18027:80 -v "$LAB27/site:/usr/share/nginx/html:ro,Z" "$IMAGE27"
podman inspect lf-course27-web --format '{{.Id}}'
curl --retry 3 --retry-all-errors --retry-delay 1 --max-time 5 -fsS http://127.0.0.1:18027/
podman exec lf-course27-web test ! -e /tmp/lf27-ephemeral
sha256sum "$LAB27/site/index.html"

Even if created with the same name, the container ID changed. The body B of the host document and the SHA-256 b1601d1a277b5d3b6aab1018d58594ac3cd4eab0e2195d95064a83aedd95523b were preserved, but /tmp/lf27-ephemeral inside the container was not present. This was confirmed under the condition of deleting the container and creating a new one, not simply stopping and starting it.

Because a bind mount continues to use the path outside the container, deleting the container does not mean the data is deleted. However, if the host file is deleted or the storage device is damaged, the data will be lost, so a separate backup is necessary. You can also use a named volume managed by Podman, but in this lecture, the actual regeneration and hash comparison was performed on the bind mount mentioned above.

Understanding user ID mapping and file ownership

id
podman exec lf-course27-web id
podman exec lf-course27-web id nginx
podman top lf-course27-web user huser
podman unshare cat /proc/self/uid_map

The default execution user of the container was root, but the host user column of podman top was 1000. The container UID 101 of the Nginx worker appeared as 524388 on the host. It is not necessary for the image's username to match the host's username; the numeric mapping in each namespace actually affects access.

Mapping of this VM Values visible on the host
Container UID 0 Executed by regular user UID 1000
Container UIDs from 1 to 65536 Range allocated starting from subuid 524288
Container UID 101 524288 + (101 - 1) = 524388

This number was checked as the default mapping for this user. --userns The value may differ with options or other users' subuid ranges. The podman unshare documentation explains why a regular user's UID and GID appear as 0 in that namespace.

Below is an example of changing ownership and reverting it for only a new test file. Do not apply it to web materials or the entire home directory. If the file already exists, do not overwrite and stop.

test ! -e "$LAB27/ownership.txt" || { printf 'Inspect the existing test file and stop.\n' >&2; exit 1; }
printf 'mapped uid test\n' > "$LAB27/ownership.txt"
chmod 0600 "$LAB27/ownership.txt"
podman unshare chown 101:101 "$LAB27/ownership.txt"
stat -c '%u:%g %a' "$LAB27/ownership.txt"
podman unshare stat -c '%u:%g %a' "$LAB27/ownership.txt"
cat "$LAB27/ownership.txt"
podman unshare chown 0:0 "$LAB27/ownership.txt"
stat -c '%u:%g %a' "$LAB27/ownership.txt"
rm -- "$LAB27/ownership.txt"

Host lookup was 524388:524388 600 , lookup inside the namespace was 101:101 600 . In this state, the regular user cat failed with a permission denied error as expected. When reverted with podman unshare chown 0:0 , it became 1000:1000 600 on the host. It is important not to confuse 0 in this namespace with root on the host.

Check logout behavior and clean up the container

The source user setting was Linger=no. When the source SSH session ended, the lab observed that the Nginx container received a SIGTERM and shut down normally along with the termination of the systemd user manager. podman run -d means running without attaching to the terminal, and it is not a setting that guarantees service continuation after reboot or logout. For long-term execution, both user service and session persistence conditions must be configured together.

podman ps -a
podman inspect lf-course27-web --format '{{.State.Status}}'
podman logs --tail 20 lf-course27-web
loginctl show-user "$(id -un)" -p Linger
podman rm -f lf-course27-web
restorecon -RFv "$LAB27/site"
ls -Zd "$LAB27/site" "$LAB27/site/index.html"
stat -c '%u:%g %a' "$LAB27/site/index.html"
ss -lnt 'sport = :18027' 

After confirming that it is your practice container, only remove its name. To keep materials as regular home files when the container no longer uses the path, you can restore the context. In this environment, container_file_t, which is user-configurable, was maintained with only restorecon -R, and after applying -RF to the exact practice path, it returned to user_home_t. It is not applied to other container paths in use.

After cleanup, the practice container and listener on port 18027 were gone, and Document B remained with UID·GID 1000, mode 0644. Existing SSH, Nginx, firewall, hosts, and fstab settings, as well as the original user mappings, were preserved. The Podman packages, policy support and image cache remained. Package changes should be compared with a recorded baseline; do not delete existing local SELinux overrides merely to match another lab.