0%

docker镜像仓库harbor搭建中讲解了如何安装harbor,这一篇文章主要讲如何使用harbor。

创建用户

输入用户信息,创建用于push image的用户。

创建项目

输入项目信息。

进入项目,在成员标签下,把刚才创建的user用户以开发人员的角色,添加到此项目下。

推入镜像

我们先下载一个nginx的镜像

1
docker pull nginx:1.16.1

查看镜像

1
2
3
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx 1.16.1 55c440ba1ecb 3 days ago 127MB

修改tag

1
docker tag 55c440ba1ecb 172.16.64.233/my-project/nginx:1.16.1

推镜像

1
2
3
docker push 172.16.64.233/my-project/nginx:1.16.1
The push refers to repository [172.16.64.233/my-project/nginx]
Get https://172.16.64.233/v2/: dial tcp 172.16.64.233:443: connect: connection refused

所以需要加入insecure-registries配置

1
vi /etc/docker/daemon.json

添加如下内容:

1
2
3
{
"insecure-registries": ["172.16.64.233"]
}

重启docker

1
systemctl restart docker

再次推送

1
2
3
4
5
6
docker push 172.16.64.233/my-project/nginx:1.16.1
The push refers to repository [172.16.64.233/my-project/nginx]
37ec257a56ed: Preparing
567538016328: Preparing
488dfecc21b1: Preparing
denied: requested access to the resource is denied

出现权限不够的错误。

所以需要登录。之前我们注册了一个user用户。

1
2
3
4
5
6
7
8
docker login 172.16.64.233
Username: user
Password:
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

再次push

1
2
3
4
5
6
docker push 172.16.64.233/my-project/nginx:1.16.1
The push refers to repository [172.16.64.233/my-project/nginx]
37ec257a56ed: Pushed
567538016328: Pushed
488dfecc21b1: Pushed
1.16.1: digest: sha256:5f281748501a5ad9f5d657fc6067ac6187d62be2a811c460deee1504cabddc51 size: 948

成功。

在harbor页面里,也可以看到此镜像了。

拉取镜像

我们可以换一台机器,拉取镜像。

1
2
docker pull 172.16.64.233/my-project/nginx:1.16.1
Error response from daemon: Get https://172.16.64.233/v2/: dial tcp 172.16.64.233:443: connect: connection refused

和前面处理这个问题的方式一样,在/etc/docker/daemon.json加入如下内容。

1
2
3
{
"insecure-registries": ["172.16.64.233"]
}

并重启docker

1
systemctl restart docker

再次拉取镜像

1
2
3
4
5
6
7
docker pull 172.16.64.233/my-project/nginx:1.16.1
1.16.1: Pulling from my-project/nginx
bc51dd8edc1b: Pull complete
60041be5685b: Pull complete
5ad6baa9b36b: Pull complete
Digest: sha256:5f281748501a5ad9f5d657fc6067ac6187d62be2a811c460deee1504cabddc51
Status: Downloaded newer image for 172.16.64.233/my-project/nginx:1.16.1

成功拉取。

高可用设置

如果需要搭几个harbor节点,则可以到仓库管理同步管理标签中设置同步规则。

然后再在harbor的前端,通过nginx做一个负载均衡即可。

本篇文章将介绍高可用docker镜像仓库的搭建。

下载harbor安装文件

https://github.com/goharbor/harbor/releases

找到最新发行版本,v1.9.4harbor-offline-installer-v1.9.4.tgz

1
wget https://github.com/goharbor/harbor/releases/download/v1.9.4/harbor-offline-installer-v1.9.4.tgz

文件有点大,要下载一会儿。

安装harbor

先解压

1
2
tar -xvf harbor-offline-installer-v1.9.4.tgz
cd harbor

当直接执行install.sh安装命令时,会报如下错误:

1
2
3
4
5
./install.sh
➜ Please set hostname and other necessary attributes in harbor.yml first. DO NOT use localhost or 127.0.0.1 for hostname, because Harbor needs to be accessed by external clients.
Please set --with-notary if needs enable Notary in Harbor, and set ui_url_protocol/ssl_cert/ssl_cert_key in harbor.yml bacause notary must run under https.
Please set --with-clair if needs enable Clair in Harbor
Please set --with-chartmuseum if needs enable Chartmuseum in Harbor

所以先修改harbor.yml

1
vi harbor.yml

hostname改为当前服务器的ip

1
2
#hostname: reg.mydomain.com
hostname: 172.16.64.233

同时需要注意一下,harbor的数据默认是存放在这个位置的:

1
2
# The default data volume
data_volume: /data

我们还可以看到管理员登录的账号和密码也是在这里配置的。

1
2
3
4
# The initial password of Harbor admin
# It only works in first time to install harbor
# Remember Change the admin password from UI after launching Harbor.
harbor_admin_password: Harbor12345

如果要换到其他地方存放数据,需要修改这个配置。

再次运行安装命令,又会报如下错误:

1
2
3
4
5
6
./install.sh

[Step 0]: checking installation environment ...

Note: docker version: 18.06.3
✖ Need to install docker-compose(1.18.0+) by yourself first and run this script again.

所以需要安装docker-compose,具体方法请参考 CentOS环境安装Docker

1
yum install docker-compose

再次执行安装

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
./install.sh

[Step 0]: checking installation environment ...

Note: docker version: 18.06.3

Note: docker-compose version: 1.18.0

[Step 1]: loading Harbor images ...
62b223a46a15: Loading layer [==================================================>] 34.29MB/34.29MB
40f95e7c4d8c: Loading layer [==================================================>] 12.77MB/12.77MB
87bc69f1a650: Loading layer [==================================================>] 55.42MB/55.42MB
2d7b6446b66d: Loading layer [==================================================>] 5.632kB/5.632kB
4fff34e50f40: Loading layer [==================================================>] 37.38kB/37.38kB
5e79cfafc57c: Loading layer [==================================================>] 55.42MB/55.42MB
Loaded image: goharbor/harbor-core:v1.9.4
57c193635092: Loading layer [==================================================>] 115.8MB/115.8MB
48c741dd71e6: Loading layer [==================================================>] 12.23MB/12.23MB
bca1df60136e: Loading layer [==================================================>] 2.048kB/2.048kB
3ded12c0b4d9: Loading layer [==================================================>] 48.13kB/48.13kB
1ab30734b178: Loading layer [==================================================>] 3.072kB/3.072kB
09dcb0a00864: Loading layer [==================================================>] 12.28MB/12.28MB
Loaded image: goharbor/clair-photon:v2.1.0-v1.9.4
b3a6b161a0f0: Loading layer [==================================================>] 7.039MB/7.039MB
1ed6312f133c: Loading layer [==================================================>] 196.6kB/196.6kB
fee283579213: Loading layer [==================================================>] 172kB/172kB
1946b2964bfc: Loading layer [==================================================>] 15.36kB/15.36kB
026952c4573d: Loading layer [==================================================>] 3.584kB/3.584kB
37bd829992ae: Loading layer [==================================================>] 10.84MB/10.84MB
Loaded image: goharbor/harbor-portal:v1.9.4
0fa4e197a1e0: Loading layer [==================================================>] 10.84MB/10.84MB
Loaded image: goharbor/nginx-photon:v1.9.4
9f4e1ee20fe3: Loading layer [==================================================>] 9.009MB/9.009MB
eb044190906a: Loading layer [==================================================>] 42.31MB/42.31MB
04e55b2b95d5: Loading layer [==================================================>] 2.048kB/2.048kB
41efcb18a521: Loading layer [==================================================>] 3.072kB/3.072kB
16903b9eaf51: Loading layer [==================================================>] 42.31MB/42.31MB
Loaded image: goharbor/chartmuseum-photon:v0.9.0-v1.9.4
19ccaba72e02: Loading layer [==================================================>] 2.56kB/2.56kB
bf35853b2d08: Loading layer [==================================================>] 1.536kB/1.536kB
facfe762a35b: Loading layer [==================================================>] 75.33MB/75.33MB
cfcf6d4e7653: Loading layer [==================================================>] 42.65MB/42.65MB
c497e06e4e96: Loading layer [==================================================>] 157.2kB/157.2kB
f444f52f4af6: Loading layer [==================================================>] 3.01MB/3.01MB
Loaded image: goharbor/prepare:v1.9.4
12f86854bc80: Loading layer [==================================================>] 80.2MB/80.2MB
5e76c79bec2e: Loading layer [==================================================>] 3.072kB/3.072kB
694b3e7869d5: Loading layer [==================================================>] 59.9kB/59.9kB
27609e3dd221: Loading layer [==================================================>] 61.95kB/61.95kB
Loaded image: goharbor/redis-photon:v1.9.4
01c4d294000a: Loading layer [==================================================>] 9.005MB/9.005MB
e836fee5658c: Loading layer [==================================================>] 3.072kB/3.072kB
ac9add5e34a0: Loading layer [==================================================>] 2.56kB/2.56kB
1af6a0c8f2bb: Loading layer [==================================================>] 21.76MB/21.76MB
692f3a6593bb: Loading layer [==================================================>] 21.76MB/21.76MB
Loaded image: goharbor/registry-photon:v2.7.1-patch-2819-2553-v1.9.4
50d697c7c241: Loading layer [==================================================>] 9.004MB/9.004MB
ccc72da8223b: Loading layer [==================================================>] 6.239MB/6.239MB
d8f9724c0195: Loading layer [==================================================>] 16.04MB/16.04MB
813deff8bdee: Loading layer [==================================================>] 28.24MB/28.24MB
27eeaef358bd: Loading layer [==================================================>] 22.02kB/22.02kB
52a7091247e7: Loading layer [==================================================>] 50.52MB/50.52MB
Loaded image: goharbor/notary-server-photon:v0.6.1-v1.9.4
391081d598f3: Loading layer [==================================================>] 50.36MB/50.36MB
6e82a6bf9097: Loading layer [==================================================>] 3.584kB/3.584kB
f44a631c4f72: Loading layer [==================================================>] 3.072kB/3.072kB
c841d5236832: Loading layer [==================================================>] 2.56kB/2.56kB
253571258f05: Loading layer [==================================================>] 3.072kB/3.072kB
88d0f16c60e6: Loading layer [==================================================>] 3.584kB/3.584kB
a4499b4f52d1: Loading layer [==================================================>] 12.29kB/12.29kB
Loaded image: goharbor/harbor-log:v1.9.4
b94d1cd23704: Loading layer [==================================================>] 63.49MB/63.49MB
7108c9c351ce: Loading layer [==================================================>] 56.37MB/56.37MB
013a04104e87: Loading layer [==================================================>] 5.632kB/5.632kB
c91b8f37358e: Loading layer [==================================================>] 2.048kB/2.048kB
aa04ed1247cb: Loading layer [==================================================>] 2.56kB/2.56kB
ea3d1b630734: Loading layer [==================================================>] 2.56kB/2.56kB
9dd11aa8e16a: Loading layer [==================================================>] 2.56kB/2.56kB
69fab71b0bc5: Loading layer [==================================================>] 10.24kB/10.24kB
Loaded image: goharbor/harbor-db:v1.9.4
573233339cd8: Loading layer [==================================================>] 12.77MB/12.77MB
1c4fa76d32f8: Loading layer [==================================================>] 48.14MB/48.14MB
Loaded image: goharbor/harbor-jobservice:v1.9.4
401a522fd2d5: Loading layer [==================================================>] 9.005MB/9.005MB
93bfd55aee1a: Loading layer [==================================================>] 3.072kB/3.072kB
41bc5eeff535: Loading layer [==================================================>] 21.76MB/21.76MB
768368529512: Loading layer [==================================================>] 3.072kB/3.072kB
d0f0f102247d: Loading layer [==================================================>] 8.661MB/8.661MB
32b9c7908fb4: Loading layer [==================================================>] 30.42MB/30.42MB
Loaded image: goharbor/harbor-registryctl:v1.9.4
f8bf76e63a50: Loading layer [==================================================>] 14.61MB/14.61MB
9cc53a4748a9: Loading layer [==================================================>] 28.24MB/28.24MB
ae2e3edc6219: Loading layer [==================================================>] 22.02kB/22.02kB
43599ec252a3: Loading layer [==================================================>] 49.09MB/49.09MB
Loaded image: goharbor/notary-signer-photon:v0.6.1-v1.9.4
713f7d39cadb: Loading layer [==================================================>] 338.3MB/338.3MB
dc092fe63769: Loading layer [==================================================>] 119.8kB/119.8kB
Loaded image: goharbor/harbor-migrator:v1.9.4


[Step 2]: preparing environment ...
prepare base dir is set to /usr/local/software/harbor
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
Generated and saved secret to file: /secret/keys/secretkey
Creating harbor-log ... done
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir


Creating registry ... done
Creating harbor-core ... done
Creating network "harbor_harbor" with the default driver
Creating nginx ... done
Creating registry ...
Creating redis ...
Creating harbor-db ...
Creating harbor-portal ...
Creating registryctl ...
Creating harbor-core ...
Creating nginx ...
Creating harbor-jobservice ...

✔ ----Harbor has been installed and started successfully.----

Now you should be able to visit the admin portal at http://172.16.64.233 .
For more details, please visit https://github.com/goharbor/harbor .

看到这些信息就算是成功安装了。如下所示,访问http://172.16.64.233就可以了。

通过用户名admin和默认密码Harbor12345,可以成功登录。

关闭harbor

进入harbor目录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
docker-compose down
Stopping harbor-jobservice ... done
Stopping nginx ... done
Stopping harbor-core ... done
Stopping registryctl ... done
Stopping harbor-db ... done
Stopping harbor-portal ... done
Stopping registry ... done
Stopping redis ... done
Stopping harbor-log ... done
Removing harbor-jobservice ... done
Removing nginx ... done
Removing harbor-core ... done
Removing registryctl ... done
Removing harbor-db ... done
Removing harbor-portal ... done
Removing registry ... done
Removing redis ... done
Removing harbor-log ... done
Removing network harbor_harbor

mvn clean package -Dmaven.test.skip=true

1
2
3
4
5
6
7
8
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ springboot-mybatis ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ springboot-mybatis ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.20.1:test (default-test) @ springboot-mybatis ---
[INFO] Tests are skipped.

不拷贝,不编译test文件夹里面的内容了。