Harbor私有镜像仓库搭建

Harbor是VMware公司最近开源的企业级Docker Registry项目, 其目标是帮助用户迅速搭建一个企业级的Docker registry服务。

前置条件

  • Linux host: docker 17.06.0-ce+ and docker-compose 1.18.0+ .

    docker和docker-compse的安装自行百度,注意版本

  • 下载离线安装包 Harbor release

下载并解压

1
2
3
4
wget https://github.com/goharbor/harbor/releases/download/v2.0.0/harbor-offline-installer-v2.0.0.tgz
github网速贼慢,耐心等待。。。
tar -zxvf harbor-offline-installer-v1.8.1.tgz -C /opt/app

配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cd /opt/app/harbor
./prepare
发现生成了docker-compose.yml文件
vim vim harbor.yml
修改一下内容:

hostname: harbor.***.com
# http related config
http:
port: 9292

harbor_admin_password: Harbor12345
database:
password: root123

更多配置参考官方文档: configure-yml-file

安装

1
2
3
4
5
6
7
8
9
10
./install.sh

查看docker-compose安装的docker镜像
root@huaheng:/opt/app/harbor# docker-compose ps | grep harbor
harbor-core /harbor/start.sh Up
harbor-db /entrypoint.sh postgres Up 5432/tcp
harbor-jobservice /harbor/start.sh Up
harbor-log /bin/sh -c /usr/local/bin/ ... Up 127.0.0.1:1514->10514/tcp
harbor-portal nginx -g daemon off; Up 80/tcp
registryctl /harbor/start.sh

访问

输入域名访问 http://harbor.test.com

image.png

默认账号密码: admin / Harbor12345

创建项目 mcgrady


这里不勾选公开,默认为私有项目

登录到docker私服

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
docker login harbor.test.com
输入用户名密码后,出现以下错误
Error response from daemon: Get https://harbor.huahengmxf.com:9200/v2/: http: server gave HTTP response to HTTPS client

是因为没有配置私服的地址

vim /etc/docker/daemon.json

{
"registry-mirrors": ["https://n0st2wzy.mirror.aliyuncs.com"],
"insecure-registries":["harbor.test.com:9292"]
}



[root@hadoop01 ~]# docker login harbor.huahengmxf.com
Username: admin
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

出现 sucess表示登录成功

推送镜像到Harbor仓库

这里找一个本地已有的mysql镜像作为测试进行推送
看到新建的项目mcgrady中描述,推送镜像分为两步:

  1. tag
1
2
3
docker image ls
docker tag mysql:5.7.22 harbor.test.com:9292/mcgrady/mysql:5.7.22

  1. push
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@hadoop01 ~]# docker push harbor.test.com:9292/mcgrady/mysql:5.7.22
The push refers to repository [harbor.test.com:9292/mcgrady/mysql]
a968f24d4187: Pushed
f8cb294d5d80: Pushed
489bddb9c55e: Pushed
22b402e93939: Pushed
8aeebb3964c1: Pushed
94f8d8f5acbf: Pushed
c0c26734fb83: Pushed
4801a487d51a: Pushed
aae63f31dee9: Pushed
6f8d38b0e2b6: Pushed
cdb3f9544e4c: Pushed
5.7.22: digest: sha256:e744510d4d03fddd1162651312afd1e591cf33b051c6f29ed64b9a3e64b97aa7 size: 2621


刷新harbor管控台可以看到刚刚推送的镜像

客户端重新拉取新推送的镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@hadoop01 ~]# docker pull harbor.test.com:9292/mcgrady/mysql:5.7.22
5.7.22: Pulling from mcgrady/mysql
be8881be8156: Pull complete
c3995dabd1d7: Pull complete
9931fdda3586: Pull complete
bb1b6b6eff6a: Pull complete
a65f125fa718: Pull complete
2d9f8dd09be2: Pull complete
37b912cb2afe: Pull complete
79592d21cb7f: Pull complete
00bfe968d82d: Pull complete
79cf546d4770: Pull complete
2b3c2e6bacee: Pull complete
Digest: sha256:e744510d4d03fddd1162651312afd1e591cf33b051c6f29ed64b9a3e64b97aa7
Status: Downloaded newer image for harbor.test.com:9292/mcgrady/mysql:5.7.22
[root@hadoop01 ~]# docker images | grep mysql
harbor.huahengmxf.com:9292/mcgrady/mysql 5.7.22 6bb891430fb6 22 months ago 372MB

参考文档: