企业级镜像仓库 Harbor 的安装与配置

Harbor

Posted by BlueFat on Monday, February 10, 2020

官方地址 https://github.com/goharbor/harbor

安装 docker 17.03.0-ce+ and docker-compose 1.18.0+

安装Docker

https://docs.docker.com/engine/install/centos/

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine \
                  podman \
                  runc


sudo yum install -y yum-utils
sudo yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

sudo sed -i 's@download.docker.com@mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

安装Docker-compose

https://docs.docker.com/compose/install/other/

curl -SL https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose

chmod +x /usr/local/bin/docker-compose 

安装Harbor

cd /usr/local/
wget https://github.com/goharbor/harbor/releases/download/v2.6.2/harbor-offline-installer-v2.6.2.tgz
tar xf harbor-offline-installer-v2.6.2.tgz
cd harbor
harbor.yml.tmpl harbor.yml

配置

harbor.yml.tmpl harbor.yml

vim harbor.yml

hostname: registry.sundayhk.com
port: 8099
#https: 禁用https,使用其他nginx代理https
#  port: 443
#  certificate: 
#  private_key: 
external_url: https://registry.sundayhk.com
harbor_admin_password: Harbor12345
data_volume: /data/harbor

安装

./install.sh

账户密码 admin:Harbor12345

启动/停止

docker-compose stop
docker-compose start

nginx代理

upstream harbor {
    server 192.168.10.228:8099;
}
server {
    listen 80;
    server_name registry.sundayhk.com;
    return 308 https://$server_name$request_uri;
}
server {
    listen  443 ssl;
    server_name registry.sundayhk.com;
    index index.html;

    ssl_certificate      /data/ssl/acme/registry.sundayhk.com.pem;
    ssl_certificate_key  /data/ssl/acme/registry.sundayhk.com.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    location / {
        proxy_pass http://192.168.10.228:8099;
        client_max_body_size 0; # 放开上传文件大小限制
        proxy_connect_timeout 90;
        proxy_read_timeout 90;
        proxy_buffer_size 4k;
        proxy_buffers 6 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;
    }
}

访问https://registry.sundayhk.com

系统管理 - 用户管理 - 创建用户 项目 - Library - 成员 - 添加用户

docker登陆

[root@harbor harbor]# docker login registry.sundayhk.com
Username: sunday
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

上传镜像

# 测试镜像
[root@harbor ~]# docker pull nginx:alpine
[root@harbor ~]# docker tag nginx:alpine registry.sundayhk.com/library/nginx:alpine
# 上传
[root@harbor ~]# docker push registry.sundayhk.com/library/nginx:alpine
The push refers to repository [registry.sundayhk.com/library/nginx]
0618d1e529fa: Pushed 
6e96dd581d79: Pushed 
acf5e0b2cf08: Pushed 
d51445d70778: Pushed 
b96b16a53835: Pushed 
994393dc58e7: Pushed 
alpine: digest: sha256:fcba10206c0e29bc2c6c5ede2d64817c113de5bfaecf908b3b7b158a89144162 size: 1568

拉取镜像

# 删除原来镜像
[root@harbor ~]# docker rmi registry.sundayhk.com/library/nginx:alpine
# 拉取
[root@harbor ~]# docker pull registry.sundayhk.com/library/nginx:alpine