docker私有库创建流程

目录

docker私有库介绍

为什么选择私有docker镜像?

 构建私有镜像库工具

Docker Registry 是官方提供的工具,可以用于构建私有镜像库,相当于官网的docker hub ,也相当于阿里云Docker Registry

将本地镜像推送到私有库案例 

下载镜像 registry

 运行私有库Registry

 上传镜像到私有库

查询私有库有哪些镜像

 上传镜像到私有库


docker私有库介绍

为什么选择私有docker镜像?

1、官方Docker Hub 地址为:https://hub.docker.com/,我们完全可以把自己的镜像放到这里,就像我们可以把代码放在github一样,但是,比较坑的是,在中国大陆,访问太慢,不是主流选择。

2、阿里云看到趋势,解决了中国大陆访问慢的问题,但是收费,所以......

3、公司有些机密的东西不想对外公开

综上所述,私有库应运而生。

 构建私有镜像库工具

Docker Registry 是官方提供的工具,可以用于构建私有镜像库,相当于官网的docker hub ,也相当于阿里云Docker Registry

Registry 

英 [ˈredʒɪstri]   美 [ˈredʒɪstri]  
登录;域名注册局;注册局;注册表项;注册机构

将本地镜像推送到私有库案例 

下载镜像 registry

docker pull registry

[root@localhost ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
2408cc74d12b: Pull complete
ea60b727a1ce: Pull complete
c87369050336: Pull complete
e69d20d3dd20: Pull complete
fc30d7061437: Pull complete
Digest: sha256:bedef0f1d248508fe0a16d2cacea1d2e68e899b2220e2258f1b604e1f327d475
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
tomcat        latest    451d25ef4583   2 weeks ago     483MB
redis         latest    2e50d70ba706   2 weeks ago     117MB
ubuntu        latest    27941809078c   5 weeks ago     77.8MB
registry      latest    773dbf02e42e   6 weeks ago     24.1MB
hello-world   latest    feb5d9fea6a5   9 months ago    13.3kB
centos        latest    5d0da3dc9764   9 months ago    231MB
redis         6.0.8     16ecd2772934   20 months ago   104MB
[root@localhost ~]#

 运行私有库Registry

相当于有了本地的docker hub

 docker run -d -p 5000:5000 -v /zzyyuse/myregistry/:/tmp/registry --privileged=true registry

默认情况下,仓库被创建在容器的/var/lib/registry 目录下(如果没有-v /zzyyuse/myregistry/:/tmp/registry 的指定容器卷映射),建议自行用容器卷映射,方便于宿主机联调。

[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
tomcat        latest    451d25ef4583   2 weeks ago     483MB
redis         latest    2e50d70ba706   2 weeks ago     117MB
ubuntu        latest    27941809078c   5 weeks ago     77.8MB
registry      latest    773dbf02e42e   6 weeks ago     24.1MB
hello-world   latest    feb5d9fea6a5   9 months ago    13.3kB
centos        latest    5d0da3dc9764   9 months ago    231MB
redis         6.0.8     16ecd2772934   20 months ago   104MB
[root@localhost ~]# docker run -d -p 5000:5000 -v /zzyyuse/myregistry/:/tmp/registry --privileged=true registry
f1793c8eecb0ee9329328fa32964c00922ee6fd2123c9030fdc46886aba5f1c5
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE      COMMAND                  CREATED          STATUS          PORTS                                       NAMES
f1793c8eecb0   registry   "/entrypoint.sh /etc…"   18 seconds ago   Up 17 seconds   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   kind_meninsky
[root@localhost ~]#

 上传镜像到私有库

查询私有库有哪些镜像

curl -XGET http://192.168.2.250:5000/v2/_catalog

[root@localhost ~]# curl -XGET http://192.168.2.250:5000/v2/_catalog
{"repositories":[]}
[root@localhost ~]#

 上传镜像到私有库

docker tag 镜像:Tag Host:Port/Repository:Tag

相当于打个标签,本地存储一份,为上传做准备

[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
tomcat        latest    451d25ef4583   2 weeks ago     483MB
redis         latest    2e50d70ba706   2 weeks ago     117MB
ubuntu        latest    27941809078c   5 weeks ago     77.8MB
registry      latest    773dbf02e42e   6 weeks ago     24.1MB
hello-world   latest    feb5d9fea6a5   9 months ago    13.3kB
centos        latest    5d0da3dc9764   9 months ago    231MB
redis         6.0.8     16ecd2772934   20 months ago   104MB
[root@localhost ~]# docker tag redis:6.0.8 192.168.2.250:5000/redis:6.0.8
[root@localhost ~]# docker images
REPOSITORY                 TAG       IMAGE ID       CREATED         SIZE
tomcat                     latest    451d25ef4583   2 weeks ago     483MB
redis                      latest    2e50d70ba706   2 weeks ago     117MB
ubuntu                     latest    27941809078c   5 weeks ago     77.8MB
registry                   latest    773dbf02e42e   6 weeks ago     24.1MB
hello-world                latest    feb5d9fea6a5   9 months ago    13.3kB
centos                     latest    5d0da3dc9764   9 months ago    231MB
192.168.2.250:5000/redis   6.0.8     16ecd2772934   20 months ago   104MB
redis                      6.0.8     16ecd2772934   20 months ago   104MB
[root@localhost ~]#

由于Docker Registry 默认不支持http推送,需要修改配置。

如果没有这个文件,需要新建,修改完成后,建议重启docker

docker restart dockerID

systemctl restart docker  重启docker

[root@localhost ~]# vi /etc/docker/daemon.json
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# cat /etc/docker/daemon.json
{
 "insecure-registries":["192.168.2.250:5000"]
}


[root@localhost ~]# systemctl restart docker
[root@localhost ~]# systemctl  status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-07-12 10:59:48 CST; 56s ago
     Docs: https://docs.docker.com
 Main PID: 2640 (dockerd)
    Tasks: 12
   Memory: 39.4M
   CGroup: /system.slice/docker.service
           └─2640 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Jul 12 10:59:47 localhost.localdomain dockerd[2640]: time="2022-07-12T10:59:47.810895945+08:00" level=info msg="Firewalld: docker zone already ...turning"
Jul 12 10:59:48 localhost.localdomain dockerd[2640]: time="2022-07-12T10:59:48.104874173+08:00" level=info msg="Firewalld: interface docker0 al...turning"
Jul 12 10:59:48 localhost.localdomain dockerd[2640]: time="2022-07-12T10:59:48.133898388+08:00" level=info msg="Firewalld: interface docker0 al...turning"
Jul 12 10:59:48 localhost.localdomain dockerd[2640]: time="2022-07-12T10:59:48.493784307+08:00" level=info msg="Default bridge (docker0) is ass...address"
Jul 12 10:59:48 localhost.localdomain dockerd[2640]: time="2022-07-12T10:59:48.635151872+08:00" level=info msg="Firewalld: interface docker0 al...turning"
Jul 12 10:59:48 localhost.localdomain dockerd[2640]: time="2022-07-12T10:59:48.762267749+08:00" level=info msg="Loading containers: done."
Jul 12 10:59:48 localhost.localdomain dockerd[2640]: time="2022-07-12T10:59:48.827467409+08:00" level=info msg="Docker daemon" commit=a89b842 g...20.10.17
Jul 12 10:59:48 localhost.localdomain dockerd[2640]: time="2022-07-12T10:59:48.827655792+08:00" level=info msg="Daemon has completed initialization"
Jul 12 10:59:48 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
Jul 12 10:59:48 localhost.localdomain dockerd[2640]: time="2022-07-12T10:59:48.890500070+08:00" level=info msg="API listen on /var/run/docker.sock"
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]#
[root@localhost ~]#

重启后,重新开启Docker Registry,并推送镜像到私有镜像库,让后通过一个get请求验证

[root@localhost ~]# docker images
REPOSITORY                 TAG       IMAGE ID       CREATED         SIZE
tomcat                     latest    451d25ef4583   2 weeks ago     483MB
redis                      latest    2e50d70ba706   2 weeks ago     117MB
ubuntu                     latest    27941809078c   5 weeks ago     77.8MB
registry                   latest    773dbf02e42e   6 weeks ago     24.1MB
hello-world                latest    feb5d9fea6a5   9 months ago    13.3kB
centos                     latest    5d0da3dc9764   9 months ago    231MB
192.168.2.250:5000/redis   6.0.8     16ecd2772934   20 months ago   104MB
redis                      6.0.8     16ecd2772934   20 months ago   104MB
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@localhost ~]# docker run -d -p 5000:5000 -v /zzyyuse/myregistry/:/tmp/registry --privileged=true registry
bb2d9dadab802a4107c8026842ebc507774cb547ff356ca4887c2f838e6651ad
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE      COMMAND                  CREATED         STATUS         PORTS                                       NAMES
bb2d9dadab80   registry   "/entrypoint.sh /etc…"   4 seconds ago   Up 2 seconds   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   strange_merkle
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# docker push 192.168.2.250:5000/redis:6.0.8
The push refers to repository [192.168.2.250:5000/redis]
138f6b0e7b1b: Pushed
284d84e7fd93: Pushed
1178a53d8ff1: Pushed
223b15010c47: Pushed
832f21763c8e: Pushed
d0fe97fa8b8c: Pushed
6.0.8: digest: sha256:7599352c534698f628f3c8f3d8845317d2bb0b15525ab69c3e04b1a7596db18b size: 1572
[root@localhost ~]# curl -XGET http://192.168.2.250:5000/v2/_catalog
{"repositories":["redis"]}
[root@localhost ~]#

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

haowll

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值