Podman QuickStart

Install

Install Link

brew install podman
podman machine init
podman machine start

podman machine init --cpus=4 --disk-size=64 --memory=6144
podman machine start podman-machine-default

Ubuntu 环境安装和测试

Ubuntu 默认安装的版本是3.4.4 在启动的时候会抱错:

Error: unable to start host networking: "could not find \"gvproxy\" in one of [/usr/local/libexec/podman /usr/local/lib/podman /usr/libexec/podman /usr/lib/podman]"

尝试安装最新版本的podman,官方安装文档: https://podman.io/getting-started/installation
文档说明,podman 的安装包是放在 opensuse.org 这个网站上的,但是安装包存放的目录已经发生了变化,大家根据自己的实际环境进行安装。不会的,抄下面作业:

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_22.04/Release.key \
  | gpg --dearmor \
  | sudo tee /etc/apt/keyrings/devel_kubic_libcontainers_unstable.gpg > /dev/null
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/devel_kubic_libcontainers_unstable.gpg]\
    https://download.opensuse.org/repositories/devel:kubic:libcontainers:unstable/xUbuntu_22.04/ /" \
  | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:unstable.list > /dev/null
sudo apt-get update -qq
sudo apt-get -y install podman

Could not access KVM kernel module: Permission denied

在启动 vm machine 时,有可能抱错: Permission denied

$  podman machine start
Starting machine "podman-machine-default"
Waiting for VM ...
Error: qemu exited unexpectedly with exit code 1, stderr: Could not access KVM kernel module: Permission denied
qemu-system-x86_64: -accel kvm: failed to initialize kvm: Permission denied

官方推荐的做法是将当前系统用户添加到 kvm 用户组中,但是我本机还没有 kvm 用户组,所以直接给 /dev/kvm 加 666 权限: sudo chmod 666 /dev/kvm
系统中如果存在 kvm group,可以尝试如下命令

sudo usermod -a -G kvm "yourUserName"
sudo usermod -a -G libvirtd "yourUserName"

Remote无法访问容器

容器启动后,通过port mapping, 已经看到该port listen。telnet localhost port 没有问题,但是 telnet IP port 死活不同,无语……

开启和关闭root 权限

Tips: 切换root 模式前后,相互看不到对方模式下的Images

podman machine set --rootful
podman machine set --rootful=false

podman system connection list                                                                                                                  Name                         URI                                                               Identity                                  Default
podman-machine-default       ssh://core@localhost:62426/run/user/110553204/podman/podman.sock  /Users/wakun/.ssh/podman-machine-default  false
podman-machine-default-root  ssh://root@localhost:62426/run/podman/podman.sock                 /Users/wakun/.ssh/podman-machine-default  true

The system helper service is not installed; the default Docker API socket
address can't be used by podman. If you would like to install it run the
following commands:

    sudo /usr/local/Cellar/podman/4.1.1/bin/podman-mac-helper install
    podman machine stop; podman machine start

You can still connect Docker API clients by setting DOCKER_HOST using the
following command in your terminal session:

    export DOCKER_HOST='unix:///Users/wakun/.local/share/containers/podman/machine/podman-machine-default/podman.sock'

Podman machine 管理

  • 查看创建的虚拟机 podman machine list
  • 虚拟机在本地磁盘存储位置: /Users/wakun/.local/share/containers/podman/machine/qemu/podman-machine-default_fedora-coreos-37.20221211.2.0-qemu.x86_64.qcow2x
  • 通过 qemu 启动的虚拟机配置 : /Users/wakun/.config/containers/podman/machine/qemu
  • 修改虚拟机硬件配置 :podman machine set --help
  • 进入虚拟机,可以sudo 到 root 账号 :podman machine ssh podman-machine-default

Pull Image 加速

目前DockerHub pull image会限制速度,中科大的mirror 已经暂停外部访问。

通过 Ucloud 容器镜像库进行加速

Link: https://console.ucloud.cn/uhub/uhub/accelerate_image

通过 创建加速任务 创建需要pull 的image mirror。本地login ucloud repo podman login uhub.service.ucloud.cn 之后,就可以pull 对应的 ucloud image mirror
Ucloud 容器镜像库

通过阿里云镜像加速下载

  • 进入podman machine 内部,修改 /etc/containers/registries.conf 或者 /etc/containers/registries.conf.d/999-podman-machine.conf 配置文件,增加如下
[[registry]]
location = "docker.io"
[[registry.mirror]]
location = "xxx.mirror.aliyuncs.com"

Troubleshooting

Homebrew 没有更新导致下载的qemu 版本低,虚拟机无法启动

一开始本低 Homebrew 没有更新,podman 依赖的 qemu 7.0.0_1 版本过低,这个版本的qemu 有Bug。更新Homebrew 后,https://github.com/Homebrew/homebrew-core/blob/master/Formula/qemu.rb 版本升级到 qemu--7.2.0.monterey.bottle.tar.gz 之后启动正常。Double check 本低的 qemu 版本号: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/qemu.rb

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值