我们在使用Docker时 下载镜像一般都是在外网下载并使用。可是当我们没有外网时,我们便自己搭建私有仓库。
1.利用registry镜像搭建私有仓库
1.配置阿里云镜像加速器
(1)访问阿里云并登陆
(2)获取镜像加速器
(3).配置镜像加速器
[root@foundation66 Desktop]# cd /etc/docker/
[root@foundation66 docker]# ls
certs.d key.json
#1.修改配置文件
[root@foundation66 docker]# vim daemon.json
###########################
{
"registry-mirrors": ["https://2izot27h.mirror.aliyuncs.com"]
}
#2.重载守护进程
[root@foundation66 docker]# systemctl daemon-reload
#3.重启docker服务
[root@foundation66 docker]# systemctl restart docker
2.从阿里云拉取registry镜像
[root@foundation66 ~]# docker pull registry
[root@foundation66 ~]# docker images
3.创建私有仓库(容器)
#1.创建私有仓库(容器),-d表示打入后台,-p表示端口映射,-v表示挂载数据卷
[root@foundation66 ~]# docker run -d --name registry -p 5000:5000 -v /opt/registry:/var/lib/registry registry
270b16b732b06ae4c6745a5873141dc7fe79c324ba54f11b86bf251bffbacb05
#2.查看容器
[root@foundation66 ~]# docker ps
测试:
1.上传自定义镜像到私有仓库
#1.查看镜像
[root@foundation66 ~]# docker images
#2.tag表示重命名
[root@foundation66 ~]# docker tag busybox:v1 localhost:5000/busybox:v1
[root@foundation66 docker]# docker images
#3.上传镜像到私有仓库
[root@foundation66 ~]# docker push localhost:5000/busybox:v1
[root@foundation66 ~]# cd /opt/registry/
[root@foundation66 registry]# ls
docker
[root@foundation66 registry]# cd docker/
[root@foundation66 docker]# tree .
bash: tree: command not found...
[r