Windows配置Podman

玖亖伍
2025-04-16 / 0 评论 / 11 阅读 / 正在检测是否收录...

安装

需提前配置好 WSL2, 此处不提
  1. podman Releases 下载最新的 podman--setup.exe(比如 podman-5.4.2-setup.exe, 后续均以 5.4.2 版本为例)
注: 可使用 https://ghp.miaostay.com/ 进行加速
  1. 执行 podman-5.4.2-setup.exe 进行安装,安装过程选择 WSL 而不是 Hyper-V,安装完成后,就能在终端中使用 podman 命令(安装过程会自动添加到环境变量 PATH)了
  2. 执行 podman.exe machine init --cpus 2 --disk-size 40 --memory 2048 进行初始化, 不出意外的话会失败,类似提示如下:
Looking up Podman Machine image at quay.io/podman/machine-os-wsl:5.4 to create VM
Error: pinging container registry quay.io: Get "http://quay.io/v2/": read tcp 10.98.8.153:64494->3.217.61.179:80: wsarecv: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

需要配置加速,见下一步。

  1. 上一步的执行已经在用户目录下生成了配置目录 .config/containers, 在其中创建文件 registries.conf, 内容如下:
unqualified-search-registries = ["docker.io"]

[[registry]]
prefix = "docker.io"
location = "docker.nju.edu.cn"
insecure = true

[[registry]]
prefix = "ghcr.io"
location = "ghcr.nju.edu.cn"
insecure = true

[[registry]]
prefix = "gcr.io"
location = "gcr.nju.edu.cn"
insecure = true

[[registry]]
prefix = "quay.io"
location = "quay.nju.edu.cn"
insecure = true

再次执行上一步的操作,则能成功,成功输出如下:

Looking up Podman Machine image at quay.io/podman/machine-os-wsl:5.4 to create VM
Getting image source signatures
Copying blob 4bab67f5f540 done   |
Copying config 44136fa355 done   |
Writing manifest to image destination
4bab67f5f5409e348e66f7b568233744e2d1ea1969989adcc575ba79aa453b79
Extracting compressed file: podman-machine-default-amd64: done
Importing operating system into WSL (this may take a few minutes on a new WSL install)...
操作成功完成。
Configuring system...
Machine init complete
To start your machine run:

        podman machine start
  1. 执行命令 podman.exe machine list 查看列表, 输出如下:

    NAME                     VM TYPE     CREATED         LAST UP     CPUS        MEMORY      DISK SIZE
    podman-machine-default*  wsl         13 minutes ago  Never       2           2GiB        40GiB
  2. 为节省磁盘空间,将其移动到其他目录(假设为 D:\wsl2-disk\podman-machine-default):

    # 停止虚拟机
    podman machine stop
    # 关闭wsl
    wsl --shutdown
    # 导出
    wsl --export podman-machine-default podman.tar
    # 注销默认 podman 对于的 wsl 虚拟机以释放空间
    wsl --unregister podman-machine-default
    # 导入到指定位置
    wsl --import podman-machine-default D:\wsl2-disk\podman-machine-default podman.tar --version 2
    # 删除导出文件
    del podman.tar
    # 启动
    podman machine start
0

评论 (0)

取消