当我们有自己的镜像比如项目镜像,为了方便大家的使用,可以将镜像推到私服中,再次用到镜像时从私服上拉取即可。
步骤:
- 创建镜像
- 配置http传输
- 启动registry
- 推送镜像
- 查看私服中是否存在已推镜像
创建镜像
可以查看前面将项目打包为镜像https://blog.csdn.net/a____a23456/article/details/106124646
配置http传输
私服的传输方式默认为https,所以需要配置http的传输
vim /etc/docker/daemon.json
{
"bip":"172.17.0.1/24",
"registry-mirrors": ["https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn","http://hub-mirror.c.163.com","https://reg-mirror.qiniu.com/"],
"insecure-registries": ["192.168.236.134:5000"]
}
###insecure-registries为私服的ip地址和端口号组合,多个私服中间用,分割
修改daemon.json后需要重新加载daemon.json并重启docker
systemctl daemon-reload
systemctl restart docker
启动registry 查看私服中镜像
docker run -d --name reg -p 5000:5000 registry #启动仓库
http://192.168.236.134:5000/v2/_catalog #查看所有镜像,只有镜像名称,没有版本号
http://192.168.236.134:5000/v2/demo/tags/list #查看镜像demo详细信息 比如: name :demo,tag:test
推送镜像
在推送镜像前需要设置镜像的版本tag,就像Git中的不同版本
docker tag demo:test 192.168.236.134:5000/demo:test #将镜像demo:test重命名为192.168.236.134:5000/demo:test作为一个版本
192.168.236.134:5000/demo:test代表私服的地址和端口,这样以后方便知道是哪个私服的镜像
docker push 192.168.236.134:5000/demo:test #推送镜像
查看私服中是否存在已推镜像
http://192.168.236.134:5000/v2/_catalog
http://192.168.236.134:5000/v2/demo/tags/list
192.168.236.134 为linux虚拟机ip,在启动registry时指定-p,使得可以在windows系统访问容器。
当本虚拟机没有镜像时可以从私服中拉取
docker pull 192.168.236.134:5000/demo:test