瘦了就帅了 / PVE CT虚拟机环境下Podman的安装

Created Tue, 22 Jul 2025 18:49:39 +0800 Modified Sun, 05 Oct 2025 02:09:22 +0000

修改CT虚拟机

修改特权容器

nano /etc/pve/lxc/<CTID>.conf
  • 删除或注释掉 unprivileged: 1 这一行。
  • 确保没有 lxc.idmap 相关的UID/GID映射配置(如有则删除)。

CT虚拟机必须是特权容器,但创建CT虚拟机时,默认为非特权容器,要特别注意!!!

安装

apt update
# 安装 Podman
apt install -y podman pipx iptables # iptables必须安装,否则netavark无法运行
# 安装 podman-compose
apt install pipx \
    && pipx install podman-compose \
    && echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc \
    && . ~/.bashrc

# 验证安装
podman version ; podman-compose version
# 防火墙一定要加这条,否则容器之间的名称解析无法工作
iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT

配置

# 配置国内镜像源
sed -E -i.bak \
    -e 's/^# (unqualified-search-registries = ).+$/\1["docker.io"]/' \
    -e 's/^# (\[\[registry\]\])$/\1/' \
    -e 's/^# (prefix = ).+"$/\1"docker.io"/' \
    -e '0,\/^# (location = ).+"$/s//\1"docker.1ms.run"/' \
    -e '0,\/^# (\[\[registry.mirror\]\])$/s//\1/' \
    -e '0,\/^# (location = ).*"$/s//\1"registry.cn-hangzhou.aliyuncs.com"/' \
    /etc/containers/registries.conf
# nano /etc/containers/registries.conf
unqualified-search-registries = ["docker.io"]

[[registry]]
prefix = "docker.io"
location = "docker.1ms.run"

[[registry.mirror]]
location = "registry.cn-hangzhou.aliyuncs.com"  # 可选备用

其实命令与Docker一致,非常方便好用。