Founding prices until 15 December: 30% off Pro, locked for life. See pricing

RHCSA containers and NFS: podman services and automounts on a VM

Run a rootless podman container as a service that starts at boot, and mount NFS shares at boot and on demand with autofs. Practised on a Rocky Linux VM.

LinuxUpdated 27 November 20262 min read

Containers and network file systems close the RHCSA objectives. Both need a kernel of your own: podman uses namespaces and mounts, and NFS mounts are made by the kernel. BrokenCluster's lab machines can't do either, so practise these on a Rocky Linux 9 VM (how to build one). Before you start, practise the systemd part in the browser with Turn a script into a service.

1. A rootless container

As an ordinary user (create web with useradd web and log in as it with SSH or machinectl shell web@, not su, so the user's systemd instance runs):

podman search nginx
skopeo inspect docker://docker.io/library/nginx:stable     # labels and command, no download
podman pull docker.io/library/nginx:stable
mkdir -p ~/site && echo hi > ~/site/index.html
podman run -d --name site -p 8080:80 -v ~/site:/usr/share/nginx/html:Z nginx:stable
curl localhost:8080

:Z relabels the directory so the container may read it with SELinux enforcing. Without it the page returns 403.

2. As a service that starts at boot

podman rm -f site
mkdir -p ~/.config/containers/systemd
vim ~/.config/containers/systemd/site.container
[Container]
Image=docker.io/library/nginx:stable
PublishPort=8080:80
Volume=%h/site:/usr/share/nginx/html:Z

[Install]
WantedBy=default.target
systemctl --user daemon-reload
systemctl --user start site
systemctl --user status site
sudo loginctl enable-linger web     # start at boot, without a login

Reboot the VM and check curl localhost:8080 before you log in.

3. An NFS server to practise against

On the second VM (or the same one):

sudo dnf install -y nfs-utils
sudo mkdir -p /exports/data /exports/homes/ana
echo "/exports *(rw,sync,no_root_squash)" | sudo tee /etc/exports.d/lab.exports
sudo systemctl enable --now nfs-server
sudo firewall-cmd --permanent --add-service={nfs,mountd,rpc-bind} && sudo firewall-cmd --reload

4. Mount at boot

showmount -e server             # from the client
sudo mkdir /mnt/data
sudo vim /etc/fstab             # server:/exports/data  /mnt/data  nfs  defaults,_netdev  0 0
sudo mount -a && findmnt /mnt/data

5. Mount on demand with autofs

sudo dnf install -y autofs
echo "/rhome /etc/auto.rhome" | sudo tee /etc/auto.master.d/rhome.autofs
echo "*  -rw,sync  server:/exports/homes/&" | sudo tee /etc/auto.rhome
sudo systemctl enable --now autofs
ls /rhome/ana                   # mounted the moment you open it

/rhome stays empty until something opens a name inside it; that is normal for indirect maps.

Drill

From the clean snapshot: a rootless container service that survives a reboot, an NFS mount in fstab and an autofs wildcard map, in 20 minutes. The container quiz questions check the details.

Questions

Does the container service start at boot if the user never logs in?
Only with lingering enabled: loginctl enable-linger <user>. Without it, the user's systemd instance (and the container) starts at their first login and stops at their last logout.
Quadlet or podman generate systemd?
Quadlet. podman generate systemd is deprecated in podman 4.4 and later; RHEL 9.3 and newer use Quadlet .container files, which systemd turns into services.
What does the & mean in an autofs map?
It repeats the key, the * that matched. In '* -rw nfs.lab.example.com:/homes/&', opening /rhome/ana mounts nfs.lab.example.com:/homes/ana.

Fix it yourself

A live machine in your browser, already broken. The grader checks the result.

Start the first lab

No account needed for your first tries.

More guides