一、环境准备

OS:CentOS Linux release 7.5.1804 (Core) 
IP:172.16.8.46

安装要求如下:

Centos 7.x部署Harbor镜像仓库

二、docker安装

参考https://blog.csdn.net/xiegh2014/article/details/80454019

三、安装docker-compose

curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

四、安装及配置harbor
下载离线安装包
https://github.com/goharbor/harbor/releases

已保存百度提供下载    链接:https://pan.baidu.com/s/1j6Vru5yCGNT-wXQN-4WOEw 密码:khs8
Centos 7.x部署Harbor镜像仓库

tar -xvf harbor-offline-installer-v1.6.0-rc3.tgz 
cd harbor/
./prepare 
vim harbor.cfg 
改为当前服务器IP
hostname = 172.16.8.46

Centos 7.x部署Harbor镜像仓库
登陆webui

默认用户/密码 admin/Harbor12345
http://172.16.8.46

Centos 7.x部署Harbor镜像仓库

配置本地deamon.json文件

cat /etc/docker/daemon.json 
{
  "registry-mirrors": ["https://registry.docker-cn.com", "https://docker.mirrors.ustc.edu.cn"], 
  "insecure-registries": ["172.16.8.46"],
  "max-concurrent-downloads": 10,
  "log-driver": "json-file",
  "log-level": "warn",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
    }
}

必须重启docker服务
[root@qas-k8s-harbor harbor]# systemctl restart docker.service 
        

[root@qas-k8s-harbor harbor]# docker-compose stop
Stopping harbor-db  ... done
Stopping harbor-log ... done
[root@qas-k8s-harbor harbor]# docker-compose start
Starting log         ... done
Starting registry    ... done
Starting postgresql  ... done
Starting adminserver ... done
Starting ui          ... done
Starting redis       ... done
Starting jobservice  ... done
Starting proxy       ... done
[root@qas-k8s-harbor harbor]# 

测试

[root@qas-k8s-harbor harbor]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
802b00ed6f79: Pull complete 
e9d0e0ea682b: Pull complete 
d8b7092b9221: Pull complete 
Digest: sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
Status: Downloaded newer image for nginx:latest
[root@qas-k8s-harbor harbor]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
nginx                           latest              06144b287844        7 days ago          109MB
goharbor/chartmuseum-photon     v0.7.1-v1.6.0       b67537c8726d        7 days ago          357MB
goharbor/harbor-migrator        v1.6.0              22775c4e4066        7 days ago          803MB
goharbor/redis-photon           v1.6.0              06a776379641        7 days ago          214MB
goharbor/clair-photon           v2.0.5-v1.6.0       3c5c2968147d        7 days ago          309MB
goharbor/notary-server-photon   v0.5.1-v1.6.0       4dd7df4ad4b6        7 days ago          215MB
goharbor/notary-signer-photon   v0.5.1-v1.6.0       78decf4dc4d9        7 days ago          212MB
goharbor/registry-photon        v2.6.2-v1.6.0       98bf341403a5        7 days ago          201MB
goharbor/nginx-photon           v1.6.0              71b4ae38b2e7        7 days ago          138MB
goharbor/harbor-log             v1.6.0              9de414888d83        7 days ago          203MB
goharbor/harbor-jobservice      v1.6.0              273959ce10be        7 days ago          198MB
goharbor/harbor-ui              v1.6.0              dca75f6ec7d4        7 days ago          221MB
goharbor/harbor-adminserver     v1.6.0              08b2d70c45ce        7 days ago          187MB
goharbor/harbor-db              v1.6.0              d241676e2034        7 days ago          225MB

查看镜像

[root@qas-k8s-harbor harbor]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
nginx                           latest              06144b287844        7 days ago          109MB
goharbor/chartmuseum-photon     v0.7.1-v1.6.0       b67537c8726d        7 days ago          357MB
goharbor/harbor-migrator        v1.6.0              22775c4e4066        7 days ago          803MB
goharbor/redis-photon           v1.6.0              06a776379641        7 days ago          214MB
goharbor/clair-photon           v2.0.5-v1.6.0       3c5c2968147d        7 days ago          309MB
goharbor/notary-server-photon   v0.5.1-v1.6.0       4dd7df4ad4b6        7 days ago          215MB
goharbor/notary-signer-photon   v0.5.1-v1.6.0       78decf4dc4d9        7 days ago          212MB
goharbor/registry-photon        v2.6.2-v1.6.0       98bf341403a5        7 days ago          201MB
goharbor/nginx-photon           v1.6.0              71b4ae38b2e7        7 days ago          138MB
goharbor/harbor-log             v1.6.0              9de414888d83        7 days ago          203MB
goharbor/harbor-jobservice      v1.6.0              273959ce10be        7 days ago          198MB
goharbor/harbor-ui              v1.6.0              dca75f6ec7d4        7 days ago          221MB
goharbor/harbor-adminserver     v1.6.0              08b2d70c45ce        7 days ago          187MB
goharbor/harbor-db              v1.6.0              d241676e2034        7 days ago          225MB

镜像打标记

[root@qas-k8s-harbor harbor]# docker tag 06144b287844 172.16.8.46/qas/nginx:latest
[root@qas-k8s-harbor harbor]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
172.16.8.46/qas/nginx           latest              06144b287844        7 days ago          109MB
nginx                           latest              06144b287844        7 days ago          109MB
goharbor/chartmuseum-photon     v0.7.1-v1.6.0       b67537c8726d        7 days ago          357MB
goharbor/harbor-migrator        v1.6.0              22775c4e4066        7 days ago          803MB
goharbor/redis-photon           v1.6.0              06a776379641        7 days ago          214MB
goharbor/clair-photon           v2.0.5-v1.6.0       3c5c2968147d        7 days ago          309MB
goharbor/notary-server-photon   v0.5.1-v1.6.0       4dd7df4ad4b6        7 days ago          215MB
goharbor/notary-signer-photon   v0.5.1-v1.6.0       78decf4dc4d9        7 days ago          212MB
goharbor/registry-photon        v2.6.2-v1.6.0       98bf341403a5        7 days ago          201MB
goharbor/nginx-photon           v1.6.0              71b4ae38b2e7        7 days ago          138MB
goharbor/harbor-log             v1.6.0              9de414888d83        7 days ago          203MB
goharbor/harbor-jobservice      v1.6.0              273959ce10be        7 days ago          198MB
goharbor/harbor-ui              v1.6.0              dca75f6ec7d4        7 days ago          221MB
goharbor/harbor-adminserver     v1.6.0              08b2d70c45ce        7 days ago          187MB
goharbor/harbor-db              v1.6.0              d241676e2034        7 days ago          225MB

登录harbor仓库

[root@qas-k8s-harbor harbor]# docker login 172.16.8.46 -uadmin -pHarbor12345
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Login Succeeded

上传镜像到harbor仓库

[root@qas-k8s-harbor harbor]# docker push 172.16.8.46/qas/nginx:latest
The push refers to repository [172.16.8.46/qas/nginx]
579c75bb43c0: Pushed 
67d3ae5dfa34: Pushed 
8b15606a9e3e: Pushed 
latest: digest: sha256:c0b69559d28fb325a64c6c8f47d14c26b95aa047312b29c699da10380e90b4d7 size: 948

Centos 7.x部署Harbor镜像仓库