For the complete documentation index, see llms.txt. This page is also available as Markdown.

34.3 Podman Container Management

Podman is an open-source container runtime led by Red Hat, serving as an alternative to Docker with a highly compatible command-line interface. Podman uses a daemonless architecture where each container runs as an independent process, eliminating the need for a constantly running background daemon, which improves system security and reduces the risk of single points of failure.

On the FreeBSD platform, Podman relies on the Linux compatibility layer (Linuxulator) when running Linux containers, and uses the Jail mechanism for isolation when running FreeBSD native containers. For containers running through the Linux compatibility layer, you can use the jls command to view their underlying Jail structure. Through sysctl -d security.jail.param, you can list all queryable Jail kernel parameters, which reflect the underlying Jail attributes corresponding to each container.

Installing Podman

When installing the sysutils/podman-suite meta-package, it will also install sysutils/buildah (for building container images), sysutils/podman (container runtime), sysutils/skopeo (for manipulating container images), and sysutils/catatonit (container init process).

  • Install using pkg:

# pkg install podman-suite
  • Install using Ports:

# cd /usr/ports/sysutils/podman-suite/
# make install clean
  • View post-installation configuration information:

# pkg info -D podman

Configuring the fstab File

To use Podman on FreeBSD, you need to configure filesystem mount points. fdescfs is a file descriptor filesystem provided by FreeBSD that maps process file descriptors to filesystem nodes; Podman depends on this filesystem to pass file descriptors inside containers.

Add the following line to the /etc/fstab file:

fdesc   /dev/fd         fdescfs         rw      0       0

Then execute the following command to make it take effect immediately:

Configuring the Network

Podman uses the PF (Packet Filter) firewall for address translation and traffic control of container networks, allowing containers to access external networks through the host's network interface.

If PF has not been previously configured on the system, you can directly copy the configuration example provided by Podman:

Edit the /etc/pf.conf file, replacing ix0 with the currently used network card; you can check it with the ifconfig command:

If the system already has PF running with a custom rule set, directly copying the example file will overwrite the existing configuration. In this case, you should only extract the rules related to container networking and append them to the existing /etc/pf.conf. The core content to add is as follows:

Where $ext_if needs to be replaced with the actual network card name, and the subnet 10.88.0.0/16 is the Podman default bridge subnet. After adding the rules, execute pfctl -f /etc/pf.conf to reload the configuration for it to take effect.

Next, start the PF firewall. The net.pf.filter_local=1 parameter enables PF filtering for packets destined to the local machine's address; once enabled, PF can apply NAT/rdr rules to such packets, thereby enabling network communication between containers and the host.

Creating a ZFS Storage Pool

To manage container storage resources, it is recommended to create a dedicated ZFS filesystem. The specific steps are as follows:

Create a ZFS filesystem zroot/containers and set the mount point to /var/db/containers:

Starting Services

Start the related services:

Project structure:

Testing the Ubuntu Image

After the services are started, you can test pulling the Ubuntu image to verify that Podman is working properly:

  • Test pulling the Ubuntu image:

  • View currently pulled images:

  • Print system version (only the first 5 lines):

  • Enter the container:

Testing the Nginx Container Packaged by FreeBSD Maintainers

In addition to Linux images, Podman can also run FreeBSD native containers. This section tests the Nginx container packaged by FreeBSD maintainers:

Open http://ip:8080 in a browser to access the Nginx test page.

More Usage

  • View logs:

  • View container running status:

  • Stop and remove a container:

  • Remove an image (must remove containers referencing the image first):

Using FreeBSD Containers

In addition to containers provided by third-party maintainers, you can also directly pull the official FreeBSD image from Docker Hub:

References

Last updated