(一)Harbor安装 -- 企业级Registry仓库
以下文章转自http://www.jianshu.com/p/2ebadd9a323d
根据Harbor官方描述:
Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,通过添加一些企业必需的功能特性,例如安全、标识和管理等,扩展了开源Docker Distribution。作为一个企业级私有Registry服务器,Harbor提供了更好的性能和安全。提升用户使用Registry构建和运行环境传输镜像的效率。Harbor支持安装在多个Registry节点的镜像资源复制,镜像全部保存在私有Registry中, 确保数据和知识产权在公司内部网络中管控。另外,Harbor也提供了高级的安全特性,诸如用户管理,访问控制和活动审计等。
以下进入实际操作:
部署环境:
centos-7.3
docker-1.12.6
1、下载所需的软件包:
(1)下载docker-compose:
yum install python-pip -y
pip install docker-compose
(2)下载harbor:
下载地址:
https://github.com/vmware/harbor/releases/tag/v1.2.0
下载很慢。。。。。
#harbor-offline-installer-v1.2.0.tgz离线安装包468M
(3)解压缩下载好的harbor文件,cd harbor,修改docker-compose.yml和harbor.cfg两个文件,其中docker-compose.yml主要修改registry容器参数,在network下增加如下图中框内的内容:
tar zxvf harbor-offline-installer-v1.2.0.tgz
cd harbor/
vim docker-compose.yml
harbor.cfg可以修改很多参数,这里我只修改了hostname
#vim harbor.cfg
hostname = 172.17.100.15 #你的habor服务器ip
#这里只是简单的测试,所以只编辑这一行,其他的默认不做修改;当然也可以根据你自己的实际情况做修改! 都修改完成之后,使用官方自带脚本更新参数,在harbor目录中执行./prepare
(4)执行安装脚本:
[root@localhost harbor]# ./install.sh [Step 0]: checking installation environment ... Note: docker version: 1.12.6 Note: docker-compose version: 1.16.1 [Step 1]: loading Harbor images ...
dd60b611baaa: Loading layer [==================================================>] 133.2 MB/133.2 MB
2e814f7ef645: Loading layer [==================================================>] 2.048 kB/2.048 kB
bc5742b580db: Loading layer [==================================================>] 2.048 kB/2.048 kB
5413bcdb81b0: Loading layer [==================================================>] 2.56 kB/2.56 kB
c4e2be066795: Loading layer [==================================================>] 3.584 kB/3.584 kB
a4ea62be60b0: Loading layer [==================================================>] 22.8 MB/22.8 MB
800a351ae5da: Loading layer [==================================================>] 22.8 MB/22.8 MB
Loaded image: vmware/registry:2.6.2-photon ] 229.4 kB/22.8 MB
Loaded image: photon:1.0
a39bd6a7f897: Loading layer [==================================================>] 10.95 MB/10.95 MB
6f79b8337a1f: Loading layer [==================================================>] 17.3 MB/17.3 MB
74bbd0e81dd0: Loading layer [==================================================>] 15.87 kB/15.87 kB
Loaded image: vmware/notary-photon:signer-0.5.0 ] 512 B/15.87 kB
c192a34d4ff4: Loading layer [==================================================>] 155.2 MB/155.2 MB
d012a9276a83: Loading layer [==================================================>] 10.75 MB/10.75 MB
b8befd881cb5: Loading layer [==================================================>] 10.75 MB/10.75 MB
Loaded image: vmware/clair:v2.0.1-photon ] 131.1 kB/10.75 MB
e0b3d6a2361d: Loading layer [==================================================>] 1.536 kB/1.536 kB
3a527b0785bc: Loading layer [==================================================>] 22.48 MB/22.48 MB
1efe51df48d0: Loading layer [==================================================>] 7.168 kB/7.168 kB
c20026b42fab: Loading layer [==================================================>] 5.338 MB/5.338 MB
615c076c8d0a: Loading layer [==================================================>] 9.728 kB/9.728 kB
133d7170cbc1: Loading layer [==================================================>] 2.56 kB/2.56 kB
8e5b68c51d96: Loading layer [==================================================>] 22.48 MB/22.48 MB
Loaded image: vmware/harbor-ui:v1.2.0 ] 229.4 kB/22.48 MB
9463fb852970: Loading layer [==================================================>] 75.37 MB/75.37 MB
e6020d0bad7b: Loading layer [==================================================>] 3.584 kB/3.584 kB
3fbf59525988: Loading layer [==================================================>] 3.072 kB/3.072 kB
37bccef91571: Loading layer [==================================================>] 3.072 kB/3.072 kB
Loaded image: vmware/harbor-log:v1.2.0 ] 512 B/3.072 kB
5d6cbe0dbcf9: Loading layer [==================================================>] 129.2 MB/129.2 MB
435f2dfbd884: Loading layer [==================================================>] 344.6 kB/344.6 kB
814d7b59f0cc: Loading layer [==================================================>] 4.657 MB/4.657 MB
aae399245bd0: Loading layer [==================================================>] 1.536 kB/1.536 kB
21e2ae955f72: Loading layer [==================================================>] 33.84 MB/33.84 MB
a2d0f7b84059: Loading layer [==================================================>] 25.09 kB/25.09 kB
819fa6af55b8: Loading layer [==================================================>] 3.584 kB/3.584 kB
78914c99a468: Loading layer [==================================================>] 167.7 MB/167.7 MB
36e79c658afb: Loading layer [==================================================>] 6.144 kB/6.144 kB
f73503aca003: Loading layer [==================================================>] 9.216 kB/9.216 kB
a21b39f6da59: Loading layer [==================================================>] 1.536 kB/1.536 kB
d7141699e1d4: Loading layer [==================================================>] 8.704 kB/8.704 kB
af296516d219: Loading layer [==================================================>] 4.608 kB/4.608 kB
b1ea8c380e6d: Loading layer [==================================================>] 4.608 kB/4.608 kB
Loaded image: vmware/harbor-db:v1.2.0 ] 512 B/4.608 kB
7ebf4b23a7e8: Loading layer [==================================================>] 19.6 MB/19.6 MB
Loaded image: vmware/nginx-photon:1.11.13 ] 196.6 kB/19.6 MB
bbda1562018e: Loading layer [==================================================>] 101.6 MB/101.6 MB
1171ab08cc04: Loading layer [==================================================>] 6.656 kB/6.656 kB
6df81d3a0683: Loading layer [==================================================>] 6.656 kB/6.656 kB
Loaded image: vmware/postgresql:9.6.4-photon ] 512 B/6.656 kB
1576c9b2b2cd: Loading layer [==================================================>] 7.07 MB/7.07 MB
1812ceac4c95: Loading layer [==================================================>] 7.07 MB/7.07 MB
Loaded image: vmware/harbor-adminserver:v1.2.0 ] 98.3 kB/7.07 MB
0050db551e77: Loading layer [==================================================>] 18.31 MB/18.31 MB
af9394226ea3: Loading layer [==================================================>] 18.31 MB/18.31 MB
Loaded image: vmware/harbor-jobservice:v1.2.0 ] 196.6 kB/18.31 MB
4a050fccec52: Loading layer [==================================================>] 12.16 MB/12.16 MB
d918d73369ec: Loading layer [==================================================>] 17.3 MB/17.3 MB
22898836924e: Loading layer [==================================================>] 15.87 kB/15.87 kB
Loaded image: vmware/notary-photon:server-0.5.0 ] 512 B/15.87 kB
78dbfa5b7cbc: Loading layer [==================================================>] 130.9 MB/130.9 MB
5f70bf18a086: Loading layer [==================================================>] 1.024 kB/1.024 kB
8deec01122be: Loading layer [==================================================>] 344.6 kB/344.6 kB
574ab36807f2: Loading layer [==================================================>] 1.536 kB/1.536 kB
d8f2cde2eef8: Loading layer [==================================================>] 20.48 kB/20.48 kB
eaa3924b054e: Loading layer [==================================================>] 5.12 kB/5.12 kB
8aa2c772121c: Loading layer [==================================================>] 184.3 MB/184.3 MB
c3014bbccb0b: Loading layer [==================================================>] 8.704 kB/8.704 kB
978a35efaa8c: Loading layer [==================================================>] 4.608 kB/4.608 kB
c2385ae7d6e5: Loading layer [==================================================>] 16.6 MB/16.6 MB
Loaded image: vmware/harbor-notary-db:mariadb-10.1.10 ] 196.6 kB/16.6 MB [Step 2]: preparing environment ...
Clearing the configuration file: ./common/config/adminserver/env
Clearing the configuration file: ./common/config/ui/env
Clearing the configuration file: ./common/config/ui/app.conf
Clearing the configuration file: ./common/config/ui/private_key.pem
Clearing the configuration file: ./common/config/db/env
Clearing the configuration file: ./common/config/jobservice/env
Clearing the configuration file: ./common/config/jobservice/app.conf
Clearing the configuration file: ./common/config/registry/config.yml
Clearing the configuration file: ./common/config/registry/root.crt
Clearing the configuration file: ./common/config/nginx/nginx.conf
loaded secret from file: /data/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/env
Generated configuration file: ./common/config/registry/config.yml
Generated configuration file: ./common/config/db/env
Generated configuration file: ./common/config/jobservice/env
Generated configuration file: ./common/config/jobservice/app.conf
Generated configuration file: ./common/config/ui/app.conf
Generated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
The configuration files are ready, please use docker-compose to start the service. [Step 3]: checking existing instance of Harbor ... [Step 4]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ...
Creating harbor-log ... done
Creating harbor-db ...
Creating registry ...
Creating harbor-db
Creating harbor-adminserver ...
Creating registry
Creating registry ... done
Creating harbor-ui ...
Creating harbor-ui ... done
Creating harbor-jobservice ...
Creating nginx ...
Creating harbor-jobservice
Creating nginx ... done ✔ ----Harbor has been installed and started successfully.---- Now you should be able to visit the admin portal at http://172.17.100.15.
For more details, please visit https://github.com/vmware/harbor . [root@localhost harbor]#
安装完成后会生成如下7个容器:
[root@harbor ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0fa29b3b4f08 vmware/harbor-jobservice:v1.2.0 "/harbor/harbor_jobse" 14 hours ago Up 14 hours harbor-jobservice
88ae89edfbec vmware/nginx-photon:1.11.13 "nginx -g 'daemon off" 14 hours ago Up 14 hours 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp nginx
8275cbdd0dc7 vmware/harbor-ui:v1.2.0 "/harbor/harbor_ui" 14 hours ago Up 14 hours harbor-ui
282e1bfc797a vmware/harbor-db:v1.2.0 "docker-entrypoint.sh" 14 hours ago Up 14 hours 3306/tcp harbor-db
fee494832b09 vmware/registry:2.6.2-photon "/entrypoint.sh serve" 14 hours ago Up 14 hours 5000/tcp registry
0a83bc5aedd5 vmware/harbor-adminserver:v1.2.0 "/harbor/harbor_admin" 14 hours ago Up 14 hours harbor-adminserver
1ed1ffbbcbd0 vmware/harbor-log:v1.2.0 "/bin/sh -c 'crond &&" 14 hours ago Up 14 hours 127.0.0.1:1514->514/tcp
Harbor容器的stop与start:
进入Harbor目录执行如下命令即可:
|
docker-compose stop /start
|
到此便安装完成了,直接打开浏览器登陆即可:
默认用户密码是:admin/Harbor12345离线
二、使用私有仓库push和pull镜像(上传,拉取镜像)
(1)docker默认是从官方拉取镜像的,并且从1.12版本之后,默认私有仓库是使用https来进行连接,所以我们这里需要进行一些相应的修改:
在另外一台docker主机修改docker启动文件,在启动命令后加入参数:--insecure-registry 172.17.100.15:5000
vim /etc/sysconfig/docker
然后使用systemctl daemon-reload一下,重启docker
(2)使用docker命令对镜像打标签并且上传至私有仓库
docker tag centos6-base:latest 172.17.100.15:5000/test/centos:6.5 #不要忘记加5000端口,否则push无法成功!
#镜像打完后,docker login登陆
docker login -u admin -pHarbor12345 172.17.100.15:5000
#推送镜像
docker push 172.17.100.15:5000/test/centos:6.5