如何配置 Podman 使用国内镜像源?_podman国内镜像
通过配置Podman的国内镜像加速站,我们又可以继续愉快的体验Podman管理容器的各项功能了。查看 podman 更多帮助信息,输入podman -h。
·
- Docker Hub,
https://docker.io - Red Hat Quay,
https://quay.io - GitHub,
https://ghcr.io - Google Container Registry,
https://gcr.io
您可以在以下文件中找到默认的 Podman 容器注册表配置文件 registries.conf:
- 全局配置文件:
/etc/containers/registries.conf - 用户配置文件:
~/.config/containers/registries.conf
您可以向此配置添加自定义或私有容器注册表。例如,google 容器注册表、AWS ECR、自托管私有注册表等。
如果你想使用注册中心的其他私有容器镜像,你可以使用命令登录到注册中心 podman。
例如,要登录到 docker hub。
podman login docker.io
登录后,您将能够使用 podman 命令从 docker hub 中拉取容器镜像。
如果您希望为特定用户提供不同的注册表配置,您可以 registries.conf 在用户目录中创建单独的容器注册表信息。
$HOME/.config/containers/registries.conf
国内直接用 podman pull 拉取镜像会很慢(可能拉取失败),所以需要配置国内镜像源来加速访问。
国内的镜像源
国内的镜像源(镜像站)加速地址有:
- 阿里云(需登录,免费),
http://<你的ID>.mirror.aliyuncs.com - 网易,
http://hub-mirror.c.163.com - 百度,
https://mirror.baidubce.com - 上海交大,
https://docker.mirrors.sjtug.sjtu.edu.cn - 南京大学,
https://docker.nju.edu.cn
以下连接不公开或已失效:
Docker中国官方镜像(已关闭),https://registry.docker-cn.com- 中国科技大学
USTC(仅供内部访问),https://docker.mirrors.ustc.edu.cn
Podman Container Registries 修改步骤
此处我们以全局配置文件方式修改容器注册表配置文件 registries.conf。
- 配置文件在
podman machine虚拟机中,连接该虚拟机并打开一个终端:
podman machine ssh [optional-machine-name]
- 备份原文件
sudo cp /etc/containers/registries.conf /etc/containers/registries.conf.bak
- 查看文件
sudo cat /etc/containers/registries.conf
输出类似(单个镜像源)配置信息如下:
# 取消从默认地址搜索的仓库域名
unqualified-search-registries = ["docker.io"]
# 自定义搜索器
[[registry]]
# 仓库前缀(镜像前缀)
prefix = "docker.io"
# 加速器地址,此处配置的 docker 中国区源
location = "registry.docker-cn.com"
# 允许通过 http 协议获取镜像
insecure = true
配置说明:
prefix是pull的时候指定的镜像前缀,如果不指定prefix则默认和location一致。location是获取镜像的地址;insecure=true表示允许通过HTTP协议来获取镜像,对于私有化部署/内网测试环境下无https证书的环境来说很有帮助。
- 编辑文件
sudo vim /etc/containers/registries.conf
配置多个镜像源:
unqualified-search-registries = ["docker.io"]
[[registry]]
prefix = "docker.io"
location = "hub-mirror.c.163.com"
insecure = true
[[registry.mirror]]
# 百度镜像源
location = "mirror.baidubce.com"
insecure = true
[[registry.mirror]]
# 网易 163 镜像源
location = "hub-mirror.c.163.com"
insecure = true
[[registry.mirror]]
# 上海交大镜像源
location = "docker.mirrors.sjtug.sjtu.edu.cn"
insecure = true
[[registry.mirror]]
# 南京大学镜像源
location = "docker.nju.edu.cn"
insecure = true
退出并保存:
:wq!
使用 shell 脚本配置:
#!/bin/bash
[ -e /etc/containers/registries.conf.BackupDir ] || mkdir /etc/containers/registries.conf.BackupDir
sudo cp /etc/containers/registries.conf /etc/containers/registries.conf.BackupDir/registries.conf.`date "+%Y%m%d%H%M%S"`.bak
printf '
unqualified-search-registries = ["docker.io"]
[[registry]]
prefix = "docker.io"
location = "hub-mirror.c.163.com"
insecure = true
[[registry.mirror]]
location = "mirror.baidubce.com"
insecure = true
[[registry.mirror]]
location = "hub-mirror.c.163.com"
insecure = true
[[registry.mirror]]
location = "docker.mirrors.sjtug.sjtu.edu.cn"
insecure = true
[[registry.mirror]]
location = "docker.nju.edu.cn"
insecure = true
' | sudo tee /etc/containers/registries.conf
检查配置是否生效
- 配置完成后,查看
podman信息:
podman info
- 运行容器测试:
podman run --name=hello-world hello-world
Podman 容器存储
每个系统用户都有自己的容器存储。这意味着,如果您尝试从不同的用户登录中提取 image,它会从远程注册表(registries.conf)中提取 image 而不是本地 image 。
例如:
- 对于
root用户,容器存储在/var/lib/containers/storage目录中; - 对于其他用户,容器存储在
$HOME/.local/share/containers/storage/目录中;
总结
通过配置 Podman 的国内镜像加速站,我们又可以继续愉快的体验 Podman 管理容器的各项功能了。查看 podman 更多帮助信息,输入 podman -h。
更多推荐


所有评论(0)