下载离线镜像
检查Docker环境
bash
docker version

Docker Hub 中registry 最新版本为 2.8.3,详见 registry . https://hub.docker.com/_/registry/tags
下载镜像
bash
docker pull registry:2.8.3

离线导出,方便在无法联网的设备上安装
bash
docker image save registry:2.8.3 -o registry.2.8.3.tar

离线安装
讲registry.2.8.3.tar
复制到目标设备上,运行下面命令导入镜像。
bash
docker load -i registry.2.8.3.tar

查询导入镜像
bash
docker images

启动
创建镜像存储路径
bash
mkdir -p /data/docker-registry/

启动仓库
bash
docker run -p 5000:5000 \
--name registry \
--restart=always \
-v /data/docker-registry/:/var/lib/registry \
-d registry:2.8.3
- 服务端口为 5000,注意开放防护墙。
- 镜像存储目录为 /var/lib/registry 需要映射主机存储目录防止容器删除后镜像丢失。

查看运行状态
bash
docker ps | grep registry

检查服务是否可以访问:
bash
curl 127.0.0.1:5000/v2/_catalog
仓库为空。
私有仓库设置
在需要访问该私有仓库的设备上,调整Docker配置文件/etc/docker/daemon.json
加入下面内容
json
{
"insecure-registries": [ "192.168.0.222:5000" ]
}
例如:

重启Docker
bash
systemctl restart docker

上传镜像到私有仓库
构建镜像
bash
mkdir hello_world
cd hello_world/

bash
cat > Dockerfile <<EOF
FROM scratch
EOF

构建镜像,并打上仓库标签, 注意仓库地址替换为实际IP或域名!
bash
docker build -t 192.168.0.222:5000/myhello:1.0.0 .

推送镜像到私有仓库
bash
docker push 192.168.0.222:5000/myhello:1.0.0
推送成功
查询一下仓库中是否存在
bash
curl 127.0.0.1:5000/v2/_catalog

从另外一台设备上从私有仓库拉取镜像
bash
docker pull 192.168.0.222:5000/myhello:1.0.0

参考文献
[1]. CNCF . Distribution Registry . 2024 . https://distribution.github.io/distribution/
[2]. yeasy . docker------入门到实践 . https://yeasy.gitbook.io/docker_practice/repository/registry
[3]. 博客园 . 持久化docker的镜像或容器的方法 . 飞天小子 . 2018.12 . https://www.cnblogs.com/zhuochong/p/10064350.html