Podman 教程

Podman 快速安装:Linux

Podman 支持在 Linux、MacOS 和 Windows 上进行安装,下面将介绍如何在 Linux 平台安装 Podman,将以 Ubuntu 24.04 TLS 和 Ubuntu 20.04 TLS 两个版本为例,其他平台读者自行完成,如 CentOS Stream、Debian、Fedora 等等。

Ubuntu 24.04 TLS

Ubuntu 24.04 LTS 作为长期支持版本,对 Podman 提供稳定支持,以下是详细安装流程:

步骤 1:更新系统包索引

首先,执行“sudo apt-get update”命令确保系统包列表最新:

root@hxstrive:~# sudo apt-get update
Get:1 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]
...
Get:56 http://archive.ubuntu.com/ubuntu noble-backports/multiverse amd64 c-n-f Metadata [116 B]
Fetched 38.4 MB in 10s (4003 kB/s)
Reading package lists... Done

步骤 2:安装 Podman

Ubuntu 24.04 的默认软件源已包含 Podman 包,直接通过 apt 安装:

root@hxstrive:~# sudo apt-get -y install podman
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
....
Setting up containernetworking-plugins (1.1.1+ds1-3ubuntu0.24.04.3) ...
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for libc-bin (2.39-0ubuntu8.3) ...

步骤 3:验证安装

安装完成后,执行“podman --version”命令检查版本以确认成功:

root@hxstrive:~# podman --version
podman version 4.9.3

上面返回 podman 版本为 4.9.3,说明安装成功。

  

Ubuntu 20.04 TLS

在 Ubuntu 20.04 上安装 Podman 可以按照以下步骤进行:

步骤一:更新系统包索引

执行“sudo apt update”命令确保系统包索引是最新:

root@hxstrive:~# sudo apt update
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [128 kB]
...
Get:42 http://archive.ubuntu.com/ubuntu focal-backports/multiverse amd64 c-n-f Metadata [116 B]
Fetched 35.1 MB in 47s (747 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
188 packages can be upgraded. Run 'apt list --upgradable' to see them.

步骤二:安装 Podman 所需的依赖包

执行“sudo apt install -y curl wget software-properties-common”命令安装依赖包,如下:

root@hxstrive:~# sudo apt install -y curl wget software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libcurl4 python3-software-properties
The following packages will be upgraded:
  curl libcurl4 python3-software-properties software-properties-common wget
5 upgraded, 0 newly installed, 0 to remove and 183 not upgraded.
Need to get 777 kB of archives.
...
Processing triggers for install-info (6.7.0.dfsg.2-5) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for dbus (1.12.16-2ubuntu2.3) ...

步骤三:添加 Podman 的官方源

Ubuntu 20.04 官方仓库中的 Podman 版本可能较旧,建议使用 Kubic 项目的源,例如:

source /etc/os-release
sudo sh -c "echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list"

运行如下:

root@hxstrive:~# source /etc/os-release
root@hxstrive:~# sudo sh -c "echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list"

步骤四:导入仓库的 GPG 密钥

root@hxstrive:~# wget -nv https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/xUbuntu_${VERSION_ID}/Release.key -O- | sudo apt-key add -
2025-10-30 22:44:43 URL:https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04/Release.key [1093/1093] -> "-" [1]
OK

步骤五:再次更新包索引

执行“sudo apt update”命令更新包索引,因为上面我们配置了 Kubic 项目的源,如下:

root@hxstrive:~# sudo apt update
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease
...
Fetched 16.6 kB in 4s (4448 B/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
183 packages can be upgraded. Run 'apt list --upgradable' to see them.

步骤六:安装 Podman

一切准备工作就绪后,执行“sudo apt install -y podman”命令开始安装 Podman,如下:

root@hxstrive:~# sudo apt install -y podman
Reading package lists... Done
Building dependency tree
Reading state information... Done
...
Processing triggers for dbus (1.12.16-2ubuntu2.3) ...
Processing triggers for initramfs-tools (0.136ubuntu6.7) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
Processing triggers for man-db (2.9.1-1) ...

步骤七:验证安装是否成功

执行“podman --version”命令,查看 podman 的版本信息,如下:

root@hxstrive:~# podman --version
podman version 3.4.2

如果安装成功,会显示类似以下的版本信息:

podman version x.x.x

安装完成后,你就可以使用 Podman 来管理容器了,它的命令与 Docker 非常相似,例如 podman run、podman ps 等。

🎉注意:Ubuntu 20.04 TLS 上面安装的 Podman 版本太旧了,建议使用 Ubuntu 24.04 TLS 安装的新版本。

点击查看官方文档:https://podman.io/docs/installation

  

说说我的看法
全部评论(
没有评论
关于
本网站专注于 Java、数据库(MySQL、Oracle)、Linux、软件架构及大数据等多领域技术知识分享。涵盖丰富的原创与精选技术文章,助力技术传播与交流。无论是技术新手渴望入门,还是资深开发者寻求进阶,这里都能为您提供深度见解与实用经验,让复杂编码变得轻松易懂,携手共赴技术提升新高度。如有侵权,请来信告知:hxstrive@outlook.com
其他应用
公众号