Docker 私有仓库

  Docker官方的Docker hub(https://hub.docker.com)是一个用于管理公共镜像的仓库,我们可以从上面拉取镜像
到本地,也可以把我们自己的镜像推送上去。但是,有时候我们的服务器无法访问互联网,或者你不希望将自己的镜
像放到公网当中,那么我们就需要搭建自己的私有仓库来存储和管理自己的镜像。

一、私有仓库搭建

一般私有仓库是在一台单独的服务器上创建

1、拉取私有仓库镜像 

[root@localhost ~]# docker pull registry

2、启动私有仓库容器 

[root@localhost ~]# docker run -id --name=registry -p 5000:5000 registry

3、打开浏览器 输入地址http://私有仓库服务器ip:5000/v2/_catalog,看到{"repositories":[]} 表示私有仓库 搭建成功

4、修改daemon.json ,在文件中添加一个key,保存退出。此步用于让 docker 信任私有仓库地址;注意将私有仓库服务器ip修改为自己私有仓库服务器真实ip 

[root@localhost ~]# vim /etc/docker/daemon.json 
{
  "registry-mirrors": ["https://iha1dvci.mirror.aliyuncs.com"],
  "insecure-registries":["192.168.1.11:5000"]
}

 5、重启docker 服务  

[root@localhost ~]# systemctl restart docker
[root@localhost ~]# docker start registry

二、将镜像上传至私有仓库

1、标记镜像为私有仓库的镜像 

[root@localhost ~]# docker tag centos:7 192.168.1.11:5000/centos:7

2、上传标记的镜像   

[root@localhost ~]# docker push 192.168.1.11:5000/centos:7

三、 从私有仓库拉取镜像  

[root@localhost ~]# docker pull 192.168.1.11:5000/centos:7

  

 

 

 

 

 

 

 

 

 

posted on 2023-04-15 13:24  草根920  阅读(290)  评论(0编辑  收藏  举报