Docker 仓库管理

仓库 ( registry ) 是一个用来存放镜像的地方,当我们执行 docker pull centos 去拉取 centos 镜像时,默认是从 Docker Hub 这个公共仓库来拉取的;

对于企业来说,使用公共仓库明显是不可行的,因此我们可以自己搭建一个私有仓库;这里我用 192.168.1.1 用来搭私有仓库 ( 相当于服务端 ) ,用 192.168.1.2 来下载/上传镜像 ( 相当于客户端 )

192.168.1.1 ( 服务端 ) 搭建私有仓库:

[root@localhost ~]$ docker pull registry                   # 下载registry镜像,这个镜像是官方提供的,我们可以用它来创建私有仓库
[root@localhost ~]$ docker run -d -p 5000:5000 registry    # 把registry镜像启动为容器,并映射宿主机的5000端口
[root@localhost ~]$ curl 127.0.0.1:5000/v2/_catalog        # 查看目前仓库里都有哪些镜像,我们还没上传镜像上去,所以是空的
{"repositories":[]}

192.168.1.2 ( 客户端 ) 上传或下载镜像:

# 假设我现在有一个镜像,我要把这个镜像上传到私有仓库:
[root@localhost ~]$ docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
centos                       latest              1e1148e4cc2c        3 weeks ago         202MB

# 需要先对镜像打一个标签,这个标签必须带有私有仓库的IP地址和端口:
[root@localhost ~]$ docker tag centos 192.168.1.1:5000/centos

# 修改配置文件,指明私有仓库的地址,并重启docker:
[root@localhost ~]$ cat /etc/docker/daemon.json 
{ "insecure-registries": ["192.168.1.1:5000"] }
[root@localhost ~]$ systemctl restart docker.service 

# 上传镜像:
[root@localhost ~]$ docker push 192.168.1.1:5000/centos

# 查看服务端是否有上传的镜像:
[root@localhost ~]$ curl 192.168.1.1:5000/v2/_catalog
{"repositories":["centos"]}

# 我们也可以下载镜像:
[root@localhost ~]$ docker pull 192.168.1.1:5000/centos

其他机器 ( 客户端 ) 如果想下载镜像,执行如下:

# 修改配置文件,指明私有仓库的地址,并重启docker:
[root@localhost ~]$ cat /etc/docker/daemon.json 
{ "insecure-registries": ["192.168.1.1:5000"] }
[root@localhost ~]$ systemctl restart docker.service 

# 下载镜像: [root@localhost ~]$ docker pull 192.168.1.1:5000/centos

     

原文地址:https://www.cnblogs.com/pzk7788/p/10191907.html