12.3 配置 Podman

Podman 旨在替代 Docker,其命令与 Docker 几乎完全兼容,用户甚至可以为其设置别名以便使用。

Podman 在 FreeBSD 上的实现基于 Jail,用户可以使用命令 jls 查看当前运行的容器。

安装 Podman

在安装 sysutils/podman-suite 元包时,会同时安装 sysutils/buildah、sysutils/podman 和 sysutils/skopeo。

  • 使用 pkg 安装

# pkg install podman-suite
  • 使用 Ports 安装:

# cd /usr/ports/sysutils/podman-suite/ 
# make install clean
  • 查看安装后的配置信息:

# pkg info -D podman
podman-5.3.2_2:
On install:                              # 安装时:
The FreeBSD port of the Podman container engine is experimental and should be
used for evaluation and testing purposes only.
# Podman 容器引擎的 FreeBSD 移植版本是实验性的,仅供评估和测试使用。

$ sudo podman run --rm quay.io/dougrabson/hello

Podman can restart containers after a host is rebooted. To enable this, use:
# Podman 可以在主机重启后自动重启容器。要启用此功能,请执行以下命令:

$ sudo sysrc podman_enable=YES

and start the container with a restart policy:
# 并使用重启策略启动容器:

$ sudo podman run -d --restart=always myimage

It is possible to run many Linux container images using FreeBSD's Linux emulation:
# 可以通过 FreeBSD 的 Linux 仿真功能运行多数 Linux 容器镜像:

$ sudo sysrc linux_enable=YES
$ sudo service linux start
$ sudo podman run --rm --os=linux alpine cat /etc/os-release | head -1
NAME="Alpine Linux"

On upgrade from podman<4.7.1:           # 当从版本小于 4.7.1 的 Podman 进行升级时:
In Podman-4.7.0 and later, registry authentication creds moved from
/run/containers/0/auth.json to /root/.config/containers/auth.json. Either move
the file to the new location or just re-authenticate to the required registries.
# 从 Podman 4.7.0 及更高版本起,注册表认证凭据已从
# /run/containers/0/auth.json 移动到 /root/.config/containers/auth.json。
# 用户可以将该文件移动到新位置,或重新登录所需的镜像注册表

配置 fstab

将下列行写入 /etc/fstab

然后执行下列命令使之立即生效:

配置网络

  • 复制配置文件

  • 编辑 /etc/pf.conf,将 ix0 替换为你当前使用的网卡,可使用命令 ifconfig 查看

  • 启动 pf

创建 ZFS 存储池

创建 ZFS 文件系统 zroot/containers,并将挂载点设置为 /var/db/containers

启动服务

测试 Ubuntu 镜像

测试拉取 Ubuntu 镜像:

  • 查看当前拉取的镜像

  • 打印系统版本(仅打印前 5 行)

  • 进入容器

测试 FreeBSD 维护者打包的 nginx 容器

在浏览器中打开 http://ip:8080 即可访问 nginx 测试页面

更多用法

  • 查看日志

  • 查看容器运行状态

  • 停止并删除容器

  • 删除镜像(必须先删除引用该镜像的容器)

拉取 FreeBSD

从 Docker Hub 拉取 FreeBSD 14.2 runtime 镜像:

更多信息请参见 freebsd/freebsd-runtime

参考文献

最后更新于

这有帮助吗?