分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
我们在上一篇文章中介绍了使用registry来创建企业私有仓库用于存储镜像,但是由于只有CUI的操作,一般拿来还要加工处理一下。
在以前曾经介绍过的Harbor其实也是基于Registry的这样一个企业级Registry的创建,在本文中将会介绍一下如何使用Harbor作简单的镜像推送等。
在写上一篇的文章时候,Harbor还是0.3.0版本,现在已经是0.4.1了。而且在dockerhub上也已经有了自己的镜像,安装也分为了online和offline两种tgz文件包了,现在已经是较为方便了,后期继续集成,是不是留下一个docker-compose.yml和可以配置的参数公开出来,这样的话安装就没有任何成本了,不过目前这个安装的成本也可以忽略不计,在非关键业务上作的改善都不是真正的改善,除非已经到了人神共愤的地步,否则可以无视。
事前准备
安装了docker1.12.2,具体安装方法参看如下
安装方法 | http://blog.csdn.net/liumiaocn/article/details/52130852 |
---|
[root@liumiaocn ~]# docker versionClient: Version: 1.12.2 API version: 1.24 Go version: go1.6.3 Git commit: bb80604 Built: OS/Arch: linux/amd64 Experimental: trueServer: Version: 1.12.2 API version: 1.24 Go version: go1.6.3 Git commit: bb80604 Built: OS/Arch: linux/amd64 Experimental: true[root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
设定insecure-registry
事前确认
[root@liumiaocn ~]# docker info |tail -n3 WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.Experimental: trueInsecure Registries: 127.0.0.0/8[root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
修改docker.service(/lib/systemd/system/docker.service)
修改前
ExecStart=/usr/bin/dockerd
- 1
修改后
ExecStart=/usr/bin/dockerd --insecure-registry 192.168.32.131
- 1
daemon-reload & restart docker
[root@liumiaocn harbor]# systemctl daemon-reload[root@liumiaocn harbor]# systemctl restart docker[root@liumiaocn harbor]#
- 1
- 2
- 3
再确认:192.168.32.131已被加入到Insecure Registries中
[root@liumiaocn harbor]# docker info |tail -n3 WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.Insecure Registries: 192.168.32.131 127.0.0.0/8[root@liumiaocn harbor]#
- 1
- 2
- 3
- 4
- 5
- 6
组件
Harbor 0.4.1用到的组件如下:
组件 | 版本 |
---|---|
Photon OS | 1.0 |
Docker Registry | 2.5 |
MySQL | 5.6 |
NGINX | 1.9 |
下载online安装包
命令:wget https://github.com/vmware/harbor/releases/download/0.4.1/harbor-online-installer-0.4.1.tgz
- 1
解压 & 修改Harbor.cfg文件
解压
命令:[root@liumiaocn ~]# tar xvpf harbor-online-installer-0.4.1.tgz
- 1
修改Harbor.cfg文件(只修正hostname就能正常动作,其余请自行探索)
[root@liumiaocn ~]# cd harbor[root@liumiaocn harbor]# cp harbor.cfg harbor.cfg.bak[root@liumiaocn harbor]# vi harbor.cfg[root@liumiaocn harbor]# diff harbor.cfg harbor.cfg.bak5c5< hostname = 192.168.32.131---> hostname = reg.mydomain.com[root@liumiaocn harbor]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
执行./prepare脚本
[root@liumiaocn harbor]# ./prepareGenerated configuration file: ./config/ui/envGenerated configuration file: ./config/ui/app.confGenerated configuration file: ./config/registry/config.ymlGenerated configuration file: ./config/db/envGenerated configuration file: ./config/jobservice/envClearing the configuration file: ./config/ui/private_key.pemClearing the configuration file: ./config/registry/root.crtGenerated configuration file: ./config/ui/private_key.pemGenerated configuration file: ./config/registry/root.crtThe configuration files are ready, please use docker-compose to start the service.[root@liumiaocn harbor]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
启动
在harbor的目录下,有docker-compose.yml文件,使用docker-compose 命令启动Harbor
命令: docker-compose up
- 1
第一次启动,本地没有相关的镜像的话,会自动直接从dockerhub上下载,所以online的安装包是需要联网的状态下使用的。
offline的安装包,展开后你会发现另外一个tgz文件,其实就是那些镜像所对应的文件,load进来就可以了。执行完毕之后,令起一个终端确认一下,可以看到下面5个镜像都被pull下来了。
[root@liumiaocn harbor]# docker images |egrep 'harbor|nginx|registry'vmware/harbor-db 0.4.1 bb0d8181f36f 2 weeks ago 324.2 MBvmware/harbor-jobservice 0.4.1 5413608c9b6a 2 weeks ago 161.7 MBvmware/harbor-ui 0.4.1 7db965490f9b 2 weeks ago 224.4 MBvmware/harbor-log 0.4.1 3ae2612dfe5e 2 weeks ago 185.3 MBregistry 2.5.0 c6c14b3960bd 11 weeks ago 33.28 MBnginx 1.9.0 7e156d496c9f 17 months ago 132.8 MB[root@liumiaocn harbor]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
缺省的Port被设定在80端口,需要改端口的自行修改docker-compose.yml
登陆harbor
输入前面设定的IP即可打开Harbor登陆界面,不能者请检查网络设定以及iptables等。
缺省的用户名和密码
缺省用户名 | 密码 |
---|---|
admin | Harbor12345 |
也可以自行再注册一个用户。
管理主界面
docker login
login的时候指定在docker.service中设定的IP。
[root@liumiaocn ~]# docker login 192.168.32.131Username: adminPassword:Login Succeeded[root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
pull busybox
在本地pull一个busybox用于之后向Harbor进行push
[root@liumiaocn ~]# docker pull busyboxUsing default tag: latestlatest: Pulling from library/busybox56bec22e3559: Pull completeDigest: sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912Status: Downloaded newer image for busybox:latest[root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
确认Harbor的library项目
Harbor缺省会创建一个library项目,可以看出当前的镜像数目是0
docker tag
[root@liumiaocn ~]# docker tag busybox:latest 192.168.32.131/library/busybox:latest[root@liumiaocn ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEbusybox latest e02e811dd08f 11 days ago 1.093 MB192.168.32.131/library/busybox latest e02e811dd08f 11 days ago 1.093 MBvmware/harbor-db 0.4.1 bb0d8181f36f 2 weeks ago 324.2 MBvmware/harbor-jobservice 0.4.1 5413608c9b6a 2 weeks ago 161.7 MBvmware/harbor-ui 0.4.1 7db965490f9b 2 weeks ago 224.4 MBvmware/harbor-log 0.4.1 3ae2612dfe5e 2 weeks ago 185.3 MBregistry 2.5.0 c6c14b3960bd 11 weeks ago 33.28 MBnginx 1.9.0 7e156d496c9f 17 months ago 132.8 MB[root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
docker push
[root@liumiaocn ~]# docker push 192.168.32.131/library/busybox:latestThe push refers to a repository [192.168.32.131/library/busybox]e88b3f82283b: Pushedlatest: digest: sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912 size: 527[root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
在Harbor上确认结果
library项目中的镜像数目已经从0变成了1
library项目的镜像仓库详细信息
docker pull
事前准备,清除本地的busybox的所有信息
[root@liumiaocn ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE192.168.32.131/library/busybox latest e02e811dd08f 11 days ago 1.093 MBbusybox latest e02e811dd08f 11 days ago 1.093 MBvmware/harbor-db 0.4.1 bb0d8181f36f 2 weeks ago 324.2 MBvmware/harbor-jobservice 0.4.1 5413608c9b6a 2 weeks ago 161.7 MBvmware/harbor-ui 0.4.1 7db965490f9b 2 weeks ago 224.4 MBvmware/harbor-log 0.4.1 3ae2612dfe5e 2 weeks ago 185.3 MBregistry 2.5.0 c6c14b3960bd 11 weeks ago 33.28 MBnginx 1.9.0 7e156d496c9f 17 months ago 132.8 MB[root@liumiaocn ~]# docker rmi 192.168.32.131/library/busybox busyboxUntagged: 192.168.32.131/library/busybox:latestUntagged: 192.168.32.131/library/busybox@sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912Untagged: busybox:latestUntagged: busybox@sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912Deleted: sha256:e02e811dd08fd49e7f6032625495118e63f597eb150403d02e3238af1df240baDeleted: sha256:e88b3f82283bc59d5e0df427c824e9f95557e661fcb0ea15fb0fb6f97760f9d9[root@liumiaocn ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEvmware/harbor-db 0.4.1 bb0d8181f36f 2 weeks ago 324.2 MBvmware/harbor-jobservice 0.4.1 5413608c9b6a 2 weeks ago 161.7 MBvmware/harbor-ui 0.4.1 7db965490f9b 2 weeks ago 224.4 MBvmware/harbor-log 0.4.1 3ae2612dfe5e 2 weeks ago 185.3 MBregistry 2.5.0 c6c14b3960bd 11 weeks ago 33.28 MBnginx 1.9.0 7e156d496c9f 17 months ago 132.8 MB[root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
docker pull
从Harbor的library项目中pull一个busybox的镜像
[root@liumiaocn ~]# docker pull 192.168.32.131/library/busybox:latestlatest: Pulling from library/busybox56bec22e3559: Pull completeDigest: sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912Status: Downloaded newer image for 192.168.32.131/library/busybox:latest[root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
成功pull到本地
[root@liumiaocn ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE192.168.32.131/library/busybox latest e02e811dd08f 11 days ago 1.093 MBvmware/harbor-db 0.4.1 bb0d8181f36f 2 weeks ago 324.2 MBvmware/harbor-jobservice 0.4.1 5413608c9b6a 2 weeks ago 161.7 MBvmware/harbor-ui 0.4.1 7db965490f9b 2 weeks ago 224.4 MBvmware/harbor-log 0.4.1 3ae2612dfe5e 2 weeks ago 185.3 MBregistry 2.5.0 c6c14b3960bd 11 weeks ago 33.28 MBnginx 1.9.0 7e156d496c9f 17 months ago 132.8 MB[root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
总结
本文是通过设定insecure-registry的方式,快速实现了在Harbor上管理镜像,可pull可push,但是Harbor如果只能做到这些,也不会有那么多追随者,比如多仓库的管理,策略的设定等等均可简单实现,在仓库管理的最佳实践方面还有很多东西可以自行探索。