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

Created Tue, 22 Jul 2025 18:49:39 +0800 Modified Tue, 02 Sep 2025 10:52:19 +0000

修改CT虚拟机

修改特权容器

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

修改sshd设置

nano /etc/ssh/sshd_config
  • PermitRootLogin 设置为 yes 或 prohibit-password(允许密钥登录)。
  • PubkeyAuthentication 设置为 yes。
  • PasswordAuthentication 设置为 no(推荐禁用密码登录以提高安全性)。

修复SSH密钥权限

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R root:root ~/.ssh

安装

apt update
# 安装 Podman
apt install 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

配置

# 配置国内镜像源
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一致,非常方便好用。