Linux Advanced 2 02 — Rootless Containers with Podman

Linux course index · Linux Advanced 2 category · Lesson 2 of 7

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This extension adds new material and links related posts from this site. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Serve a fixture with rootless Podman and verify that its port is published only on loopback.

Concepts and setup

The site discusses Docker, Vagrant, MicroK8s, and isolated lab networks. Here, an image provides the container’s starting filesystem, a bind mount exposes one chosen host path, and port publishing maps a host listener to a container port. Rootless mode avoids using host root to run the engine. It does not give the same isolation model as a VM. Use Podman as a regular user in a disposable VM. Use approved registry sources, and record a digest to identify the exact image used.

Run a loopback-only test site

lab=$(mktemp -d)
mkdir -m 755 "$lab/site"
printf 'rootless lab page\n' > "$lab/site/index.html"
chmod 644 "$lab/site/index.html"
podman info --format '{{.Host.Security.Rootless}}'
podman run -d --name oe-linux-web \
  -p 127.0.0.1:8088:80 \
  -v "$lab/site:/usr/share/nginx/html:ro,Z" \
  docker.io/library/nginx:1.28-alpine
podman port oe-linux-web
curl -fsS http://127.0.0.1:8088/

Possible output

true
...
80/tcp -> 127.0.0.1:8088
rootless lab page

Use an unused name and free port. Allow the service a moment to start. :ro applies inside the container. :Z is for private SELinux labeling of this disposable fixture, not your whole home or system data.

Inspect and remove the container

podman inspect --format '{{.State.Status}} {{.Image}}' oe-linux-web
podman logs --tail 4 oe-linux-web
podman stop oe-linux-web
podman rm oe-linux-web

Possible output

running sha256:...
... "GET / HTTP/1.1" 200 ...
oe-linux-web
oe-linux-web

Removing this container leaves the bind-mounted host folder. Remove that test folder only when done.

Questions only

Quick-check questions

  1. Why are direct remote connections not accepted here?
  2. Does :ro make the host directory read-only to the owner?

Assessment questions

  1. If curl refuses the connection, what are your first checks?
  2. Why record a digest instead of only a tag?
  3. How could you prove the file comes from the bind mount?

Questions and answers

Quick-check answers

  1. Why are direct remote connections not accepted here?
    Answer — The listener is bound to loopback.
  2. Does :ro make the host directory read-only to the owner?
    Answer — No. The option applies to the container’s mount.

Assessment answer key

  1. If curl refuses the connection, what are your first checks?
    Answer — Check podman state, logs and port mapping, then ss -ltn. Confirm no other program uses the port.
  2. Why record a digest instead of only a tag?
    Answer — The tag can point to a different build later, while the digest identifies exact image content.
  3. How could you prove the file comes from the bind mount?
    Answer — Change the host fixture to contain one unique marker, fetch it again, and compare.

Related source articles on this site

Technical references

Continue the course

Previous lesson 01 — Hardening a systemd Service. Next lesson 03 — Repeatable Configuration with Ansible.

Linux course index · Linux Advanced 2 category · Lesson 2 of 7

Leave a Reply