1、基础知识
1.1、什么仓库
仓库就类似于我们在网上搜索操作系统光盘的一个镜像站。
这里的仓库指的是Docker镜像存储的地方。
1.2、仓库分类
公有仓库:Docker hub、Docker cloud、等
私有仓库:registry、harbor等
本地仓库:在当前主机存储镜像的地方。
1.3、相关命令
]# docker help | grep -iE 'reg|repo'
pull Download an image from a registry
push Upload an image to a registry
login Log in to a registry
logout Log out from a registry
2、registry仓库实战
2.1、 流程
1、根据registry镜像创建容器
2、配置仓库权限
3、提交镜像到私有仓库
4、测试
2.2、registry仓库配置
2.2.1、下载registry镜像
2.2.2、启动registry仓库容器
docker run -d -p 5000:5000 registry
2.2.3、检查容器效果
]# curl 127.0.0.1:5000/v2/_catalog
{"repositories":[]}
2.3、Docker配置仓库地址【配置容器权限】
cat <<'CAT_END' >/etc/docker/daemon.json
{
"registry-mirrors":["https://qbd2mtyh.mirror.aliyuncs.com"],
"insecure-registries":["192.168.10.19:5000"]
}
CAT_END
systemctl restart docker
2.4、从registry仓库上传、拉取镜像测试
2.4.1、从外网仓库拉取redis镜像
2.4.2、给镜像打标签
docker tag redis:latest 192.168.10.19:5000/redis:6.0
2.4.3、推送镜像至registry仓库
docker push 192.168.10.19:5000/redis:6.0
2.4.4、从registry仓库拉以镜像至本地
]# docker pull 192.168.10.19:5000/redis:6.0
6.0: Pulling from redis
a2abf6c4d29d: Pull complete
c7a4e4382001: Pull complete
4044b9ba67c9: Pull complete
c8388a79482f: Pull complete
413c8bb60be2: Pull complete
1abfd3011519: Pull complete
Digest: sha256:563888f63149e3959860264a1202ef9a644f44ed6c24d5c7392f9e2262bd3553
Status: Downloaded newer image for 192.168.10.19:5000/redis:6.0
192.168.10.19:5000/redis:6.0
]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.10.19:5000/redis 6.0 7614ae9453d1 17 months ago 113MB