Skip to content

Podman 镜像管理与加速指南

一、Podman 镜像加速

全局配置

编辑全局配置文件 /etc/containers/registries.conf,添加以下内容以配置国内镜像源和私有镜像仓库:

unqualified-search-registries = ["docker.io", "quay.io","registry.access.redhat.com"]

[[registry]]
prefix = "docker.io"
location = "docker.io"

[[registry]]
prefix = "k8s.gcr.io"
location = "registry.aliyuncs.com/google_containers"

[[registry.mirror]]
location = "docker.mirrors.ustc.edu.cn"
[[registry.mirror]]
location = "registry.docker-cn.com"

[[registry]]
prefix = "quay.io"
location = "quay.azk8s.cn"

用户单独配置

编辑用户单独配置文件 ~/.config/containers/registries.conf,配置方式与全局配置类似。

私有镜像仓库配置

HTTP 私有仓库

例如,私有仓库地址为 http://hub.foxwho.com:5000,配置如下:

[[registry]]
prefix = "hub.foxwho.com:5000"
location = "hub.foxwho.com:5000"
insecure = true

注意去掉 http,并设置 insecure = true 以不使用 TLS。

HTTPS 私有仓库

例如,私有仓库地址为 https://hub.foxwho.com:5000,配置如下:

[[registry]]
prefix = "hub.foxwho.com:5000"
location = "hub.foxwho.com:5000"

二、删除无用镜像

删除悬空镜像

删除未被使用的悬空镜像:

podman image prune

删除所有未被实例运行引用的镜像:

podman image prune -a

三、删除无用实例

删除处于停止状态的容器实例:

podman container prune

四、清理系统

基础清理

删除悬空镜像、停止状态的容器以及构建缓存:

podman system prune

包含数据卷的清理

删除悬空镜像、停止状态的容器、构建缓存以及不再被引用的数据卷:

podman system prune --volumes

彻底清理

删除所有未被运行实例引用的镜像、容器、构建缓存和数据卷:

podman system prune -a --volumes