harbor镜像仓库

Harbor离线安装包下载地址:https://github.com/goharbor/harbor

docker-compose版本选择:https://github.com/docker/compose/releases

harbor下载

1
wget https://storage.googleapis.com/harbor-releases/release-1.9.0/harbor-offline-installer-v1.9.2-rc1.tgz

docker-compose安装

容器编排工具,执行./install.sh时需要。如果不安装,一会重启docker服务,相关的harbor容器会死掉,安装后就会被随着docker重启

1
2
curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

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
tar xf harbor-offline-installer-v1.9.2-rc1.tgz

mv harbor /opt/
/opt/harbor/prepare
prepare base dir is set to /opt/harbor
Unable to find image 'goharbor/prepare:v1.9.2' locally
v1.9.2: Pulling from goharbor/prepare
b950b5dd94ab: Pull complete
cc7bb94ca291: Pull complete
d6a642502e65: Pull complete
21510274066b: Pull complete
04998692a2c0: Pull complete
ae8f4647fe53: Pull complete
cee24c721c12: Pull complete
Digest: sha256:a647780bcd7f5fdcc9696332c9bca90f290912ecb41bd15c4c1a516450597bc2
Status: Downloaded newer image for goharbor/prepare:v1.9.2
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
Generated certificate, key file: /secret/core/private_key.pem, cert file: /secret/registry/root.crt
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir

修改配置文件中的主机名为本机域名或IP

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
136
137
138
139
140
141
142
143
144
145
grep "^hostname" /opt/harbor/harbor.yml
hostname: 192.168.98.240

/opt/harbor/install.sh

[Step 0]: checking installation environment ...

Note: docker version: 19.03.1
/usr/lib/python2.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.24.3) or chardet (2.2.1) doesn't match a supported version!
RequestsDependencyWarning)

Note: docker-compose version: 1.24.1

[Step 1]: loading Harbor images ...
6ef530defbe4: Loading layer 63.49MB/63.49MB
55872518448e: Loading layer 54.42MB/54.42MB
070787ce276e: Loading layer 5.632kB/5.632kB
1ddc8ebef7e9: Loading layer 2.048kB/2.048kB
94ec70036213: Loading layer 2.56kB/2.56kB
87f88832870d: Loading layer 2.56kB/2.56kB
208968317bf9: Loading layer 2.56kB/2.56kB
ab6259c81a01: Loading layer 10.24kB/10.24kB
Loaded image: goharbor/harbor-db:v1.9.2
92e51ca4c459: Loading layer 9.005MB/9.005MB
9e12eb4a5a82: Loading layer 3.072kB/3.072kB
913c064dae30: Loading layer 21.76MB/21.76MB
b28cae8255d8: Loading layer 3.072kB/3.072kB
890572f32fd2: Loading layer 8.661MB/8.661MB
6f00be7ade9a: Loading layer 30.42MB/30.42MB
Loaded image: goharbor/harbor-registryctl:v1.9.2
51bada9a03ba: Loading layer 78.25MB/78.25MB
bdd423614a28: Loading layer 3.072kB/3.072kB
e44c809a7328: Loading layer 59.9kB/59.9kB
07d91c85aa68: Loading layer 61.95kB/61.95kB
Loaded image: goharbor/redis-photon:v1.9.2
e0a372c4d5d3: Loading layer 10.84MB/10.84MB
Loaded image: goharbor/nginx-photon:v1.9.2
99f324455426: Loading layer 115.7MB/115.7MB
dbde533bd1f2: Loading layer 12.29MB/12.29MB
32adabde1b24: Loading layer 2.048kB/2.048kB
cdedbb7b738d: Loading layer 48.13kB/48.13kB
60eb6ca8f5f9: Loading layer 3.072kB/3.072kB
05fadada21a7: Loading layer 12.34MB/12.34MB
Loaded image: goharbor/clair-photon:v2.0.9-v1.9.2
fbe05936a49e: Loading layer 12.77MB/12.77MB
8dc691e9365f: Loading layer 55.38MB/55.38MB
c83233ecc176: Loading layer 5.632kB/5.632kB
de775c6f50f5: Loading layer 36.35kB/36.35kB
525709237f01: Loading layer 55.38MB/55.38MB
Loaded image: goharbor/harbor-core:v1.9.2
734abd864add: Loading layer 12.77MB/12.77MB
74033d37bf08: Loading layer 48.13MB/48.13MB
Loaded image: goharbor/harbor-jobservice:v1.9.2
6677f529d41e: Loading layer 9.005MB/9.005MB
019a95ff5e80: Loading layer 3.072kB/3.072kB
4b3792cedc69: Loading layer 2.56kB/2.56kB
274f5851694b: Loading layer 21.76MB/21.76MB
68e937b2af9e: Loading layer 21.76MB/21.76MB
Loaded image: goharbor/registry-photon:v2.7.1-patch-2819-2553-v1.9.2
Loaded image: goharbor/prepare:v1.9.2
0566b1894f2e: Loading layer 9.009MB/9.009MB
b99c86e48679: Loading layer 44.41MB/44.41MB
283ba1db5c52: Loading layer 2.048kB/2.048kB
701de676a8f6: Loading layer 3.072kB/3.072kB
c923d0b0255c: Loading layer 44.41MB/44.41MB
Loaded image: goharbor/chartmuseum-photon:v0.9.0-v1.9.2
ef4a961407c7: Loading layer 9.004MB/9.004MB
7cf94e5011b7: Loading layer 6.239MB/6.239MB
5c984b34ecb2: Loading layer 16.4MB/16.4MB
f06fb877e324: Loading layer 29.21MB/29.21MB
ae07ec384ebd: Loading layer 22.02kB/22.02kB
864698f2b94d: Loading layer 51.85MB/51.85MB
Loaded image: goharbor/notary-server-photon:v0.6.1-v1.9.2
c953b6400a8b: Loading layer 50.3MB/50.3MB
2ee784d17d84: Loading layer 3.584kB/3.584kB
c71f6b26fd01: Loading layer 3.072kB/3.072kB
bb6389098841: Loading layer 2.56kB/2.56kB
b63da553de9f: Loading layer 3.072kB/3.072kB
62a479d14974: Loading layer 3.584kB/3.584kB
aa3fee5917b8: Loading layer 12.29kB/12.29kB
Loaded image: goharbor/harbor-log:v1.9.2
691af8d2c981: Loading layer 14.9MB/14.9MB
7878347ee491: Loading layer 29.21MB/29.21MB
433f16e7c539: Loading layer 22.02kB/22.02kB
ad0202306aed: Loading layer 50.34MB/50.34MB
Loaded image: goharbor/notary-signer-photon:v0.6.1-v1.9.2
62247cb7cb19: Loading layer 337.8MB/337.8MB
d8b748aaf7dd: Loading layer 119.8kB/119.8kB
Loaded image: goharbor/harbor-migrator:v1.9.2
d9705202f79f: Loading layer 7.036MB/7.036MB
3fdb77b47894: Loading layer 196.6kB/196.6kB
8901bb1db41e: Loading layer 172kB/172kB
baf9307d1844: Loading layer 15.36kB/15.36kB
1dcfba9b1bd1: Loading layer 3.584kB/3.584kB
90a90fef2f80: Loading layer 10.84MB/10.84MB
Loaded image: goharbor/harbor-portal:v1.9.2

[Step 2]: preparing environment ...
prepare base dir is set to /opt/harbor
Clearing the configuration file: /config/log/logrotate.conf
Clearing the configuration file: /config/log/rsyslog_docker.conf
Clearing the configuration file: /config/nginx/nginx.conf
Clearing the configuration file: /config/core/env
Clearing the configuration file: /config/core/app.conf
Clearing the configuration file: /config/registry/config.yml
Clearing the configuration file: /config/registryctl/env
Clearing the configuration file: /config/registryctl/config.yml
Clearing the configuration file: /config/db/env
Clearing the configuration file: /config/jobservice/env
Clearing the configuration file: /config/jobservice/config.yml
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
loaded secret from file: /secret/keys/secretkey
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir

/usr/lib/python2.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.24.3) or chardet (2.2.1) doesn't match a supported version!
RequestsDependencyWarning)

[Step 3]: starting Harbor ...
/usr/lib/python2.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.24.3) or chardet (2.2.1) doesn't match a supported version!
RequestsDependencyWarning)
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-portal ... done
Creating redis ... done
Creating registryctl ... 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://192.168.98.240.
For more details, please visit https://github.com/goharbor/harbor .

docker设置仓库为harbor

docker服务启动文件

1
2
3
#ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock   注释或者将[-H fd:// --containerd=/run/containerd/containerd.sock]删除

ExecStart=/usr/bin/dockerd

这样做的目的是让daemon.json管理docker进程

2、创建docker守护进程配置文件

1
2
3
4
cat /etc/docker/daemon.json
{
"insecure-registries": ["http://192.168.98.240"]
}

镜像上传到harbor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#登陆harbor
docker login http://192.168.98.240 -u admin -p Harbor12345
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

#修改镜像name:tag为harbor仓库名
docker tag baishuming2020:latest 192.168.98.240/library/centos_web:v1

#上传镜像
docker push 192.168.98.240/library/centos_web:v1
The push refers to repository [192.168.98.240/library/centos_web]
968786242e9d: Pushed
v1: digest: sha256:d204253a33c6c2c74273fbd003cf3e14a48bcdd5c7bc10f51ccbad9e4dd39699 size: 528

常见问题

docker-compose命令无法使用
docker-compose ps
ERROR:
Can’t find a suitable configuration file in this directory or any
parent. Are you in the right directory?

1
Supported filenames: docker-compose.yml, docker-compose.yaml

原因: 当前目录没有配置文件

正确执行路径 harbor安装目录

1
2
3
4
5
6
7
8
9
10
11
12
docker-compose ps
Name Command State Ports
-----------------------------------------------------------------------------------------
harbor-core /harbor/harbor_core Up
harbor-db /docker-entrypoint.sh Up 5432/tcp
harbor-jobservice /harbor/harbor_jobservice ... Up
harbor-log /bin/sh -c /usr/local/bin/ ... Up 127.0.0.1:1514->10514/tcp
harbor-portal nginx -g daemon off; Up 8080/tcp
nginx nginx -g daemon off; Up 0.0.0.0:80->8080/tcp
redis redis-server /etc/redis.conf Up 6379/tcp
registry /entrypoint.sh /etc/regist ... Up 5000/tcp
registryctl /harbor/start.sh Exit 137