Docker搭建私有仓库Harbor

待我称王封你为后i 2021-12-11 03:15 501阅读 0赞

一、harbor介绍

Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器。

由下面几个组件组成:

  • proxy:nginx前端代理,主要是分发前端页面ui访问和镜像上传和下载流量

  • registry:镜像仓库,负责存储镜像文件

  • 核心服务:提供web ui,数据库,token认证,webhook等功能

  • 日志服务

  • database:用来存储核心服务的一些数据

    1090817-20181213170809288-1263603549.png

因为是vmware出品的,所以支持下面几种部署方式

  • 在线安装

  • 离线安装

  • ova安装,这个直接在vcenter上导入就可以了

官方最小配置

  • 2个cpu

  • 4g内存

  • 40g硬盘,因为是存储镜像的所以推荐硬盘大点

二、搭建过程

Install Docker CE

  1. root@localhost:~# apt-get update
  2. root@localhost:~# apt-get install apt-transport-https ca-certificates software-properties-common curl
  3. root@localhost:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg |sudo apt-key add -
  4. root@localhost:~# apt-key fingerprint 0EBFCD88
  5. root@localhost:~# add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  6. root@localhost:~# apt-get update
  7. root@localhost:~# apt-get install docker-ce

Install Docker-compose

  1. root@localhost:~# curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  2. root@localhost:~# chmod +x /usr/local/bin/docker-compose
  3. #查看版本
  4. root@localhost:~# docker --version
  5. Docker version 18.09.0, build 4d60db4
  6. root@localhost:~# docker-compose --version
  7. docker-compose version 1.22.0, build f46880fe

Install harbor

  1. root@localhost:~# wget https://storage.googleapis.com/harbor-releases/release-1.6.0/harbor-offline-installer-v1.6.0.tgz
  2. root@localhost:~# tar -zxvf harbor-offline-installer-v1.6.0.tgz
  3. #编辑配置文件
  4. root@localhost:~# cd harbor/
  5. root@localhost:~/harbor# vim harbor.cfg
  6. hostname = 114.112.34.27
  7. project_creation_restriction = adminonly
  8. #Python环境
  9. root@localhost:~/harbor# apt-get install python
  10. root@localhost:~/harbor# export LC_ALL=C
  11. root@localhost:~/harbor# ln -s /usr/bin/python3 /usr/bin/python
  12. #安装服务
  13. root@localhost:~/harbor# ./install.sh
  14. 看到以下内容,说明安装成功:

1090817-20181213171616893-1147557669.png

  1. 启动服务:
  2. root@localhost:~/harbor# docker-compose start
  3. Starting log ... done
  4. Starting registry ... done
  5. Starting postgresql ... done
  6. Starting adminserver ... done
  7. Starting ui ... done
  8. Starting redis ... done
  9. Starting jobservice ... done
  10. Starting proxy ... done
  11. root@localhost:~/harbor# docker-compose ps
  12. Name Command State Ports
  13. -------------------------------------------------------------------------------------------------------------------------------------
  14. harbor-adminserver /harbor/start.sh Up (healthy)
  15. harbor-db /entrypoint.sh postgres Up (healthy) 5432/tcp
  16. harbor-jobservice /harbor/start.sh Up
  17. harbor-log /bin/sh -c /usr/local/bin/ ... Up (healthy) 127.0.0.1:1514->10514/tcp
  18. harbor-ui /harbor/start.sh Up (healthy)
  19. nginx nginx -g daemon off; Up (healthy) 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp, 0.0.0.0:80->80/tcp
  20. redis docker-entrypoint.sh redis ... Up 6379/tcp
  21. registry /entrypoint.sh /etc/regist ... Up (healthy) 5000/t
  22. 配置HTTPS
  23. ##如果不做HTTPS,只需将hostname设置为IP,protocol改为HTTP即可,也不必生成CA
  24. root@localhost:~/harbor# vi harbor.cfg

1090817-20181213171726206-1776842514.png

  1. #创建目录
  2. root@localhost:~/harbor# mkdir -p /data/cert/
  3. #生成ca证书和签名
  4. root@localhost:~/harbor# openssl genrsa -out /data/cert/ca.key 2048
  5. root@localhost:~/harbor# openssl req -x509 -new -nodes -key /data/cert/ca.key -subj "/CN=test.harbor.com" -days 5000 -out /data/cert/ca.crt
  6. #启动服务
  7. root@localhost:~/harbor# ./prepare
  8. root@localhost:~/harbor# docker-compose down
  9. root@localhost:~/harbor# docker-compose up -d

测试








1

2

3

4

5

6

修改本地host,添加一行内容

114.112.34.27   test.harbor.com

 

在浏览器中访问

http://test.harbor.com/

默认用户名/密码:admin/Harbor12345

1090817-20181213171939061-726049299.png

登录成功后会看到如下页面:

1090817-20181213172002827-2116588794.png

添加项目:

1090817-20181213172255890-968779908.png

进入此项目,可以看到推送镜像的命令:

1090817-20181213172315944-1818653213.png

删除项目:

确认项目不再使用时,选中项目,点击删除

1090817-20181213172547818-1769974295.png

点击删除:

1090817-20181213172734861-571236044.png

在服务器进行测试

修改本地Docker默认仓库,指向Harbor

  1. root@localhost:/data/cert# cp ca.crt /usr/local/share/ca-certificates/
  2. root@localhost:/data/cert# update-ca-certificates
  3. #修改docker配置文件,指向Harbor
  4. root@localhost:~/harbor# vi /etc/default/docker
  5. #添加一行内容
  6. DOCKER_OPTS="--insecure-registry=test.harbor.com"
  7. #重启docker服务
  8. root@localhost:~# service docker restart







1

将本地Ubuntu镜像上传至Harbor

  1. #将本地镜像打一个tag
  2. root@localhost:~# docker tag ubuntu:16.04 test.harbor.com/paas/ubuntu:v1.0
  3. #推送到Harbor上
  4. root@localhost:~/harbor# docker push test.harbor.com/paas/ubuntu:v1.0







1

下载Harbor镜像至本地

  1. root@localhost:~/harbor# docker pull test.harbor.com/paas/ubuntu:v1.0
  2. v1.0: Pulling from paas/ubuntu
  3. Digest: sha256:078d30763ae6697b7d55e49f4cb9e61407abd2137cafb5625f131aa47c1a47af
  4. Status: Downloaded newer image for test.harbor.com/paas/ubuntu:v1.0

转发:https://www.cnblogs.com/zhaomeng/p/10115115.html

发表评论

表情:
评论列表 (有 0 条评论,501人围观)

还没有评论,来说两句吧...

相关阅读