📢注意:通常我们安装完 Podman 后,如果没有进行一些特殊配置,我们拉取镜像会失败。
Podman 在国内拉取镜像失败(如超时、连接被拒绝、速度极慢),通常是由于默认仓库(如 Docker Hub)在国内访问不稳定或被限制导致的。解决核心是配置国内镜像加速器,或直接使用国内仓库(如阿里云、网易云、华为云等)。
下面将介绍如何将 Podman 默认仓库配置为国内的仓库,解决拉取镜像失败的问题,而且国内镜像拉取镜像的速度也要快很多。
具体配置步骤如下(以 Windwos 下 Podman 为例):
步骤一:打开安装 Podman 默认创建的 Linux(名为 podman-machine-default),如下图:

步骤二:运行 cd .config/containers/ 命令进入到当前用户主目录的 .config/containers/ 目录,如下图:

步骤三:在 containers 目录中创建一个名为 registries.conf 的文件,如下图:

文件内容如下:
unqualified-search-registries = ["docker.io"] [[registry]] prefix = "docker.io" location = "docker.m.daocloud.io"
上述配置说明:
unqualified-search-registries = ["docker.io"]
定义“非全量镜像名”的默认搜索仓库。当你执行 podman pull nginx 这类命令时(只指定镜像名,未指定完整仓库地址),Podman 会自动在该列表中的仓库中搜索镜像。此处配置为 ["docker.io"],表示默认优先去 Docker Hub(docker.io)搜索镜像(如 nginx 会被补全为 docker.io/library/nginx)。
[[registry]] 区块(仓库映射配置)
这是一个数组形式的仓库配置,用于定义“镜像仓库前缀”与“实际访问地址”的映射(即镜像加速器的核心配置)。
prefix = "docker.io":表示“需要被映射的目标仓库前缀”。这里指定 docker.io,意味着所有针对docker.io 仓库的镜像拉取请求(如 docker.io/library/nginx)都会被拦截并转发。
location = "docker.m.daocloud.io":表示“实际访问的仓库地址”(即镜像加速器地址)。这里配置的是 DaoCloud(道客云)的 Docker Hub 镜像加速器。
当你拉取 docker.io 仓库的镜像时(如 podman pull docker.io/library/nginx 或简写的 podman pull nginx),Podman 会自动将请求转发到 docker.m.daocloud.io 仓库,从该加速器拉取镜像(而非直接访问国外的 docker.io),从而提升拉取速度并避免访问失败。
步骤四:执行 podman machine stop 命令停止 Podman 机器,即名为“podman-machine-default”Linux 虚拟机,如下:
C:\Users\hxstr> podman machine stop Machine "podman-machine-default" stopped successfully
步骤五:执行 podman machine start 命令启动 Podman 机器,例如:
C:\Users\hxstr> podman machine start Starting machine "podman-machine-default" This machine is currently configured in rootless mode. If your containers require root permissions (e.g. ports < 1024), or if you run into compatibility issues with non-podman clients, you can switch using the following command: podman machine set --rootful API forwarding listening on: npipe:////./pipe/docker_engine Docker API clients default to this address. You do not need to set DOCKER_HOST. time="2025-11-09T20:48:07+08:00" level=warning msg="Using cgroups-v1 which is deprecated in favor of cgroups-v2 with Podman v5 and will be removed in a future version. Set environment variable `PODMAN_IGNORE_CGROUPSV1_WARNING` to hide this warning." Machine "podman-machine-default" started successfully
步骤六:执行 podman pull 命令尝试拉取镜像,验证配置是否生效,例如:
C:\Users\hxstr> podman pull ubuntu Resolving "ubuntu" using unqualified-search registries (/home/user/.config/containers/registries.conf) Trying to pull docker.io/library/ubuntu:latest... Getting image source signatures Copying blob sha256:4b3ffd8ccb5201a0fc03585952effb4ed2d1ea5e704d2e7330212fb8b16c86a3 Copying config sha256:97bed23a34971024aa8d254abbe67b7168772340d1f494034773bc464e8dd5b6 Writing manifest to image destination 97bed23a34971024aa8d254abbe67b7168772340d1f494034773bc464e8dd5b6
根据上面输出,最新版本的 ubuntu 镜像被拉取到本地了,配置成功了……继续 Podman 的学习。