上一篇博文讲到了registry私有仓库,今天配置一下harbor仓库,harbor呢可以作为公开仓库,也可以作为私有仓库,今天就来配置一下harbor如何实现公开仓库和私有仓库。
关于registry公开仓库请访问博文:部署docker私有仓库registry
registry和harbor的区别
- registry:是一个私有镜像仓库,图形化支持较差,小型企业使用;
- harbor:支持可视化管理,支持私有仓库和公有仓库,支持镜像的管理控制;
docker harbor的优点
- vmware公司的开源镜像管理解决方案;
- 支持图形化管理;
- 方便访问和配置;
- 方便镜像访问控制;
- 支持镜像负责策略;
- 审计统计用户访问镜像使用情况;
docker harbor依赖的程序
- python;
- 安装docker;
- docker compose;
一、搭建harbor仓库
案例描述:
两台centos7.4,一台服务器端,一台客户端(测试使用);
两台服务器都要安装docker服务,我这里docker版本是19.03.9版本;
关于docker容器的安装请访问:安装docker.v19。03.9版本
1、配置docker compose
访问道云官网,找到安装docker compose,复制命令到docker服务器端:
1
2
3
4
5
|
[root@centos01 ~] # curl -l https://get.daocloud.io/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
<!--下载docker compose-->
[root@centos01 ~] # chmod +x /usr/local/bin/docker-compose <!--docker compose添加执行权限-->
[root@centos01 ~] # docker-compose -v <!--查看docker compose版本-->
docker-compose version 1.25.5, build 8a1c60f6
|
2、配置docker harbor公开仓库
1)打开github官网
打开github官网搜索harbor,再点击goharbor/harbor,再点击“releases”,根据自己所需,下载相应的版本,上传至服务器(网址如下: https://github.com/goharbor/harbor/releases 也可下载在线安装的包,我没试过,可自行尝试),如下:
2)配置harbor仓库
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
harbor-online-installer-v1.9.1.tgz <!--上传harbor压缩包-->
[root@centos01 ~] # tar zxvf harbor-online-installer-v1.9.1.tgz -c /usr/local/
<!--解压缩harbor到 /usr/local/ 目录-->
[root@centos01 ~] # cd /usr/local/harbor/ <!--进入harbor目录-->
[root@centos01 harbor] # cp harbor.yml harbor.yml.bak <!--备份harbor主配置文件-->
[root@centos01 harbor] # vim harbor.yml <!--修改harbor主配置文件-->
5 hostname : 192.168.100.10 <!--修改为docker服务器端ip地址即可-->
<!-- hostname 可以写域名,不过域名还需要更改hosts文件或者安装dns,我这里就用ip地址-->
8 http: <!--采用http协议-->
10 port: 80 <!--80端口号-->
27 harbor_admin_password: harbor12345 <!--默认密码,可以自定义-->
[root@centos01 harbor] # ./install.sh <!--安装harbor-->
[step 0]: checking installation environment ...
note: docker version: 19.03.9
note: docker-compose version: 1.25.5
……………… <!--此处省略部分内容-->
creating harbor-log ... done
creating registryctl ... done
creating redis ... done
creating harbor-portal ... done
creating registry ... done
creating harbor-db ... done
creating harbor-core ... done
creating nginx ... done
creating harbor-jobservice ... done
✔ ----harbor has been installed and started successfully.----
now you should be able to visit the admin portal at http: //www .benet.com .
for more details, please visit https: //github .com /goharbor/harbor .
<!--安装完成出现以上代码表示成功-->
[root@centos01 ~] # vim /usr/lib/systemd/system/docker.service <!--编辑此配置文件-->
14 execstart= /usr/bin/dockerd -h fd: // --containerd= /run/containerd/containerd .sock --insecure-registry 192.168.100.10:80
<!--定位到此行,后面添加“--insecure-registr”以便指定harbor的ip及其监听端口-->
[root@centos01 harbor] # systemctl daemon-reload <!--守护进程方式运行docker-->
[root@centos01 harbor] # systemctl restart docker <!--重新启动docker服务-->
[root@centos01 harbor] # docker-compose stop <!--停止所有容器-->
[root@centos01 harbor] # docker-compose start <!--启动所有容器-->
[root@centos01 harbor] # netstat -anptu |grep 80 <!--监听80端口-->
tcp6 0 0 :::80 :::* listen 23473 /docker-proxy
|
3)安装完成浏览器访问harbor仓库
4)创建一个公开仓库
5)确保image公开仓库已经创建成功
6)docker服务器端登录harbor仓库
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@centos01 ~] # docker login -uadmin -pharbor12345 192.168.100.10:80 <!--登录harbor仓库-->
warning! using --password via the cli is insecure. use --password-stdin.
warning! your password will be stored unencrypted in /root/ .docker /config .json.
configure a credential helper to remove this warning. see
https: //docs .docker.com /engine/reference/commandline/login/ #credentials-store
login succeeded <!--出现此提示表示登录成功-->
[root@centos01 ~] # docker tag tomcat:latest 192.168.100.10:80/image/nginx:nginx
<!--修改镜像标签-->
[root@centos01 ~] # docker push 192.168.100.10:80/image/nginx:nginx
<!--上传镜像到harbor仓库-->
[root@centos01 ~] # docker logout 192.168.100.10:80 <!--docker服务器退出harbor-->
removing login credentials for 192.168.100.10:80
|
7)harbor查看镜像是否上传成功
3、配置docker客户端
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<!--docker客户端安装docker服务-->
1)修改配置文件加载docker harbor服务器
[root@centos02 ~]# vim /usr/lib/systemd/system/docker.service <!--编辑此配置文件-->
execstart=/usr/bin/dockerd -h fd:// --containerd=/run/containerd/containerd.sock --insecure-registry 192.168.100.10:80
<!--定位到此行,后面添加“--insecure-registr”以便指定harbor的ip及其监听端口-->
[root@centos02 ~]# systemctl daemon-reload <!--守护进程运行docker-->
[root@centos02 ~]# systemctl restart docker <!--重新启动docker服务-->
[root@centos02 ~]# docker login -uadmin -pharbor12345 192.168.100.10:80
<!--docker客户端登录harbor-->
warning! using --password via the cli is insecure. use --password-stdin.
warning! your password will be stored unencrypted in /root/.docker/config.json.
configure a credential helper to remove this warning. see
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
login succeeded <!--登录成功-->
[root@centos02 ~]# docker pull 192.168.100.10:80/image/nginx:nginx
<!--docker客户端下载harbor公开仓库中的镜像-->
[root@centos02 ~]# docker images <!--查看docker客户端镜像-->
repository tag image id created size
192.168.100.10:80/image/nginx nginx 1b6b1fe7261e 7 days ago 647mb
|
4、创建harbor私有仓库
1)创建私有仓库
2)创建一个用户
3)将刚创建的private用户添加到private私有仓库中
4)上传镜像到harbor私有仓库
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@centos01 ~] # docker tag tomcat:latest 192.168.100.10:80/private/tomcat:tomcat
<!--docker服务器修改镜像标签-->
[root@centos01 ~] # docker login -uprivate -pharbor12345 192.168.100.10:80
<!--登录harbor私有仓库-->
warning! using --password via the cli is insecure. use --password-stdin.
warning! your password will be stored unencrypted in /root/ .docker /config .json.
configure a credential helper to remove this warning. see
https: //docs .docker.com /engine/reference/commandline/login/ #credentials-store
login succeeded <!--登录成功-->
[root@centos01 ~] # docker push 192.168.100.10:80/private/tomcat:tomcat
<!--上传镜像到private私有仓库-->
|
5)harbor查看镜像是否上传成功
6)docker客户端下载私有仓库中的镜像
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[root@centos02 ~] # docker login -uprivate -pharbor12345 192.168.100.10:80
<!--docker客户端登录harbor私有仓库-->
warning! using --password via the cli is insecure. use --password-stdin.
warning! your password will be stored unencrypted in /root/ .docker /config .json.
configure a credential helper to remove this warning. see
https: //docs .docker.com /engine/reference/commandline/login/ #credentials-store
login succeeded <!--登录成功-->
[root@centos02 ~] # docker pull 192.168.100.10:80/private/tomcat:tomcat
<!--docker客户端下载harbor私有仓库中的镜像-->
[root@centos02 ~] # docker images <!--docker客户端查看镜像是否下载成功-->
repository tag image id created size
192.168.100.10:80 /image/nginx nginx 1b6b1fe7261e 7 days ago 647mb
192.168.100.10:80 /private/tomcat tomcat 1b6b1fe7261e 7 days ago 647mb
|
7)harbor支持日志统计功能
到此这篇关于docker搭建harbor公开仓库的方法示例的文章就介绍到这了,更多相关docker搭建harbor公开仓库内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.51cto.com/14156658/2499740