6.3 Container Operations with Podman & Docker, OCI Standards & Volumes
Key Takeaways
Native Linux containers share a host kernel and use namespaces, cgroups and additional security controls. A VM typically boots its own guest kernel.
Podman can manage containers locally without a central daemon. Docker Engine uses a daemon even in rootless mode. A nonroot image user and rootless engine are separate controls.
Dockerfile or Containerfile instructions define filesystem changes and image configuration. An exec-form entrypoint can pair with overridable default arguments.
Container data in the writable layer is lost on removal. Named volumes and host binds have separate lifecycles. Relabel only an approved SELinux bind directory.
Match network driver, port publishing, identity and prune scope to the workload. Verify the version and engine before applying broad cleanup.
6.3 Container Operations with Podman & Docker, OCI Standards & Volumes
Begin with the image, the process it runs, and the host resources it may access. A conventional native Linux container uses the host kernel. A virtual machine normally boots its own guest kernel. Some container platforms run Linux inside a VM, in which case its kernel is the one the Linux container workloads share.
Isolation, runtimes and identity
Linux namespaces can give processes separate views of process IDs, networking, mounts, IPC, hostnames, and user/group mappings. A choice such as host networking deliberately shares a namespace. Cgroups account for and limit resources such as CPU, memory, I/O and task count when configured for the workload. Capabilities, seccomp and SELinux or AppArmor can restrict operations in addition to namespaces and cgroups.
| Tool or standard | Role |
|---|---|
| OCI specifications | Define runtime bundles and lifecycle, image manifests/configuration/layers, and registry distribution behavior. |
runc (runC) | A low-level OCI runtime that creates and runs a container from a prepared bundle. |
containerd | A runtime service that can manage image transfer and storage, container lifecycle and other host resources. Its runtime components can invoke an OCI runtime. |
| Docker Engine | The Docker CLI communicates with the engine daemon dockerd. A rootless deployment runs both the daemon and workloads without host root privileges where supported. |
| Podman | The local Linux engine can manage containers without a central daemon. It can run rootful or rootless and can also expose an API service for remote clients. It uses OCI runtimes such as crun or runc according to configuration. |
For example, in the usual rootless Podman mapping, suppose the invoking host UID is 1015 and the subordinate allocation for that account starts at 100000 with length 65536. The invoking UID can map to UID 0 in the rootless namespace. The subordinate range maps additional IDs in that namespace, starting at namespace UID 1 in this example. Other user namespace modes may change mappings. Confirm the actual mapping before interpreting access to a host directory. Root within a user namespace has a different range of authority from root in the host's initial namespace.
Running the workload as a nonzero UID, starting an engine rootless, and running with ordinary container isolation are separate choices. Podman containers normally run without --privileged. The privileged flag relaxes controls such as device restrictions, dropped capabilities, labels and syscall filtering. A rootless launcher is still limited by its host permissions. Use the narrowest access the workload requires and review which host files and networks it can reach.
On a system with compatible Podman and systemd, Quadlet files can declare a managed container. The systemd generator builds service units from these definitions for the relevant system or user manager. Inspect generated services and their logs in the correct manager scope.
Image references and builds
An image contains read-only filesystem layers and configuration. A container uses the image plus runtime settings and usually has a writable layer. Several images can share a layer. An image tag is a mutable name for an image reference. A digest identifies specific content, and a fully qualified source makes the registry and repository explicit. Review the source, version and any signatures required by local policy.
podman pull docker.io/library/python:3.12-slim
podman image inspect docker.io/library/python:3.12-slim
podman images
A Dockerfile or Containerfile specifies the build. The context path controls which local files are available. Avoid putting secrets in the build context or persistent image environment. Filesystem changes can create image layers, and metadata instructions can set image configuration without adding filesystem content.
| Instruction | Effect |
|---|---|
FROM | Sets the base for a build stage. An ARG can precede the first FROM. |
RUN | Executes a build-time command. A later layer that deletes a file does not remove its bytes from a lower layer. |
COPY and ADD | COPY copies the selected local files in this example. Dockerfile ADD can unpack a recognized local tar archive when default unpacking applies. The content matters in addition to the filename. |
WORKDIR and ENV | Select the working directory and set environment defaults for later instructions and the image's runtime configuration. |
USER | Sets the default user and optionally group for subsequent instructions and runtime. Choose permissions for that identity. |
ENTRYPOINT and CMD | With exec-form ENTRYPOINT, an exec-form CMD supplies default arguments here. A command argument after the image replaces CMD, and an explicit entrypoint override changes the selected entrypoint. |
EXPOSE | Documents an intended listening port. Use the engine's port-publishing options separately. |
For a lab build, create a readable lab_report.py in the context:
import os
import sys
print(f"{os.getenv('REPORT_LABEL', 'lab')}: {sys.argv[1]}")
Save this Containerfile alongside it:
FROM docker.io/library/python:3.12-slim
WORKDIR /app
COPY lab_report.py /app/lab_report.py
USER 10001:10001
ENTRYPOINT ["python", "/app/lab_report.py"]
CMD ["summary"]
On an isolated Linux lab host with suitable UID/GID mappings:
podman build -f Containerfile -t localhost/lab-report:1.0 .
podman run --name lab-report -e REPORT_LABEL=practice localhost/lab-report:1.0 details
podman logs lab-report
podman inspect lab-report
The first run prints practice: details. With the image reference alone, the defaults give lab: summary. The named container remains inspectable after the one-shot program exits if it was created without --rm. podman tag localhost/lab-report:1.0 localhost/lab-report:approved makes a second image name without copying its layers.
Container lifecycle and storage
podman run creates and starts a new container. Use podman ps -a for existing containers, podman start NAME to start a stopped container, and podman stop NAME to request a stop. Podman normally sends TERM and follows it with KILL after a configured wait if needed. A stop signal can be set by image or container configuration. Confirm the resulting state. With a verified running lab worker, podman exec lab-worker id starts an additional process in that container. podman rm NAME removes an eligible stopped container and its writable layer. Check referenced data, state and log requirements before removal.
| Storage choice | Lifetime and access |
|---|---|
| Writable container layer | Container-local changes normally survive a stop and are removed with the container. The storage driver controls implementation. |
| Named volume | podman volume create lab-results creates an engine-managed volume. Map it to an application path with -v lab-results:/results or the equivalent mount syntax. Check ownership and back up persistent data. Use podman volume inspect lab-results to identify actual storage. |
| Host bind mount | -v ./lab-fixtures:/fixtures:ro exposes a designated host path read-only. The mount can hide image content at the destination. A writable bind uses the host files directly. |
| Overlay mount | Where the Podman :O volume option is supported, it can use host content as a lower layer and keep changes in a separate upper layer. With default temporary upper storage, the changes do not persist after the container finishes. |
On an SELinux host, confirm any denial through the audit record. For an approved, dedicated bind directory, Podman :Z requests a private label and :z requests a shared label. Containers in a Podman pod may share an SELinux label. Both options can modify labels recursively on the host. Apply them only where relabeling is intended and permitted. A correct label still requires permissions for the mapped UID/GID and a writable mount if the application must write. For a private read-only lab bind, the suffix can be :ro,Z.
Prune commands remove different classes of objects. In the documented Podman implementation, podman image prune removes dangling images and -a broadens it to images without an associated container. podman container prune removes stopped containers outside pods. podman volume prune targets unused anonymous volumes by default and --all includes unused named volumes. podman network prune removes eligible unused networks. List objects, inspect dependencies and check your release's selection rules before pruning. Persistent data can be in an unused named volume.
Network selection and port mapping
Use podman network create lab-net to create a lab network using the default bridge driver. Inspect it with podman network inspect lab-net and attach a container with --network lab-net. On a supported Podman network, -p 127.0.0.1:8080:80 publishes container port 80 on the host's loopback address at port 8080. Omitting the host address can broaden exposure. Validate the actual listener, routes and firewall policy. Published access and access by direct routing to a container are different paths.
| Network | Practical choice |
|---|---|
| Bridge | A local network attaches containers to a software bridge with separate networking. Host access and port publishing depend on configuration. |
| Host | Shares the host's network namespace on native Linux. Port conflicts and access then follow host networking. |
| None | Gives the workload its own network namespace without attaching it to an external network. Local loopback can still be available. |
| Macvlan | Attaches endpoints to a parent link with separate MAC addresses. Check the switch and host policy. |
| IPvlan | Provides separate IP identities on a parent link while sharing the underlying interface's MAC in common modes. |
| Overlay | Connects workloads across hosts in a supported orchestrated deployment, such as Docker Swarm. This does not describe a local storage overlay. |
Podman's built-in bridge, macvlan and ipvlan drivers have different capabilities. In Podman, macvlan and ipvlan cannot access host interfaces from rootless networking and do not support port forwarding through those drivers. Use a topology supported by your engine and version.
On an SELinux-enforcing Linux lab host, a Podman container has an approved dedicated bind directory that this account is authorized and able to relabel. Audit shows a label mismatch. The application already has Unix read permission, needs only read access, and the directory is for one standalone container. Which mount option keeps it read-only and requests a private label?
Append :ro,Z to the bind specification
Append :ro,z to the bind specification
Append :rw to the bind specification
Keep only :ro and change the Unix mode
On a native Linux host, compare the ordinary local Podman CLI with a Docker Engine configured for rootless use. Which statement is correct?
Rootless Docker removes the Docker daemon
Podman requires the root-owned Docker socket for local commands
Both require a root-owned daemon even in rootless operation
Podman can operate locally without a central daemon, while rootless Docker still uses a daemon running without host root
In a Dockerfile build with default local archive handling, app-assets.tar.gz is a valid gzip-compressed tar archive in the local context. Which single instruction adds its extracted files to /var/www/html/ during the build?
COPY app-assets.tar.gz /var/www/html/
ADD app-assets.tar.gz /var/www/html/
EXTRACT app-assets.tar.gz /var/www/html/
RUN tar -xf app-assets.tar.gz -C /var/www/html/
Sections you finish are checked off in the contents.