什么是 Harbor?

第一次使用这个的时候是刚进公司处理的第一个任务的时候,发现 Harbor 就是一个用于存储和分发 Docker 镜像的企业级Registry 服务器。

网上找到一个 Harbor 的架构图:

Harbor 是 VMware 公司开源的企业级 DockerRegistry 项目,项目地址为 https://github.com/vmware/harbor。其目标是帮助用户迅速搭建一个企业级的 Docker registry 服务。它以 Docker 公司开源的 registry 为基础,提供了管理UI,基于角色的访问控制(Role Based Access Control),AD/LDAP集成、以及审计日志(Auditlogging) 等企业用户需求的功能,同时还原生支持中文。Harbor 的每个组件都是以 Docker 容器的形式构建的,使用 Docker Compose 来对它进行部署。

环境准备

1、自己在腾讯云买的服务器(CentOS7.3)

2、Docker 版本:17.05.0-ce

3、Docker-compose:1.17.1

4、Harbor:1.1.2

安装 Docker

因为系统是 CentOS 7.3 ,内核啥的都已经是 3.10,所以不用担心内核升级的问题,一些操作啥的在 7.x 上操作也很方便。

yum  update                             //系统版本更新vim /etc/yum.repos.d/docker.repo        //添加以下内容[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg//下面安装 Docker 引擎
yum install docker-engine  -y//安装docker引擎,此步也可作为更新docker版本的操作:先#systemctl stop docker 停止docker服务,再#yum install docker-engine 更新docker版本systemctl  enable  docker.servicesystemctl  start   docker              //启动docker守护进程docker info                            //查看docker运行情况docker -v                           //查看版本信息

修改 Docker 配置文件 /etc/default/docker 如下:

DOCKER_OPTS="--registry-mirror=http://aad0405c.m.daocloud.io"   //换成国内的镜像加速源,不然拉取镜像简直龟速,不想在吐槽了

使用 service docker restart 重启 Docker 服务即可。

或者用官方提供的方式:

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://ef017c13.m.daocloud.io

安装 Docker-compose

如果是想直接命令安装也行,

下载指定版本的docker-composesudo curl -L https://github.com/docker/compose/releases/download/1.17.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose对二进制文件赋可执行权限chmod +x /usr/local/bin/docker-compose测试下docker-compose是否安装成功docker-compose --version出现如下
docker-compose version 1.17.1, build 6d101fb

但是,这种方法简直龟速,幸好还有种方法,

见这里:https://docs.docker.com/compose/install/#install-compose

这种需要通过 Python 的 pip 安装

安装 pip

““shell
wget –no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz

tar -vxf setuptools-1.4.2.tar.gz

cd setuptools-1.4.2

python2.7 setup.py install //因为服务器自带 Python 2.7

easy_install-2.7 pip
““

安装 docker compose

pip install docker-composedocker-compose --version    //测试安装是否成功

安装 Harbor

wget https://github.com/vmware/harbor/releases/download/v1.1.2/harbor-offline-installer-v1.1.2.tgz离线安装包,也是龟速,把这个下载链接用迅雷下载,速度却贼快,嘿嘿,然后再传到服务器上去,整个过程快很多!tar -zxvf harbor-offline-installer-v1.1.2.tgz

解压缩之后,进入目录下会看到 harbor.cfg 文件,该文件就是 Harbor 的配置文件。

## Configuration file of Harbor# hostname设置访问地址,可以使用ip、域名,不可以设置为127.0.0.1或localhost
hostname = 115.159.227.249   #这里我先配置我的服务器IP地址# 访问协议,默认是http,也可以设置https,如果设置https,则nginx ssl需要设置on
ui_url_protocol = http# mysql数据库root用户默认密码root123,实际使用时修改下
db_password = root123#Maximum number of job workers in job service
max_job_workers = 3#Determine whether or not to generate certificate for the registry's token.
#If the value is on, the prepare script creates new root cert and private key
#for generating token to access the registry. If the value is off the default key/cert will be used.
#This flag also controls the creation of the notary signer's cert.
customize_crt = on#The path of cert and key files for nginx, they are applied only the protocol is set to https
ssl_cert = /data/cert/server.crt
ssl_cert_key = /data/cert/server.key#The path of secretkey storage
secretkey_path = /data#Admiral's url, comment this attribute, or set its value to NA when Harbor is standalone
admiral_url = NA#NOTES: The properties between BEGIN INITIAL PROPERTIES and END INITIAL PROPERTIES
#only take effect in the first boot, the subsequent changes of these properties
#should be performed on web ui#************************BEGIN INITIAL PROPERTIES************************#Email account settings for sending out password resetting emails.#Email server uses the given username and password to authenticate on TLS connections to host and act as identity.
#Identity left blank to act as username.
email_identity =email_server = smtp.mydomain.com
email_server_port = 25
email_username = sample_admin@mydomain.com
email_password = abc
email_from = admin <sample_admin@mydomain.com>
email_ssl = false##The initial password of Harbor admin, only works for the first time when Harbor starts.
#It has no effect after the first launch of Harbor.
# 启动Harbor后,管理员UI登录的密码,默认是Harbor12345
harbor_admin_password = Harbor12345# 认证方式,这里支持多种认证方式,如LADP、本次存储、数据库认证。默认是db_auth,mysql数据库认证
auth_mode = db_auth#The url for an ldap endpoint.
ldap_url = ldaps://ldap.mydomain.com#A user's DN who has the permission to search the LDAP/AD server.
#If your LDAP/AD server does not support anonymous search, you should configure this DN and ldap_search_pwd.
#ldap_searchdn = uid=searchuser,ou=people,dc=mydomain,dc=com#the password of the ldap_searchdn
#ldap_search_pwd = password#The base DN from which to look up a user in LDAP/AD
ldap_basedn = ou=people,dc=mydomain,dc=com#Search filter for LDAP/AD, make sure the syntax of the filter is correct.
#ldap_filter = (objectClass=person)# The attribute used in a search to match a user, it could be uid, cn, email, sAMAccountName or other attributes de
pending on your LDAP/AD  ldap_uid = uid#the scope to search for users, 1-LDAP_SCOPE_BASE, 2-LDAP_SCOPE_ONELEVEL, 3-LDAP_SCOPE_SUBTREE
ldap_scope = 3#Timeout (in seconds)  when connecting to an LDAP Server. The default value (and most reasonable) is 5 seconds.
ldap_timeout = 5# 是否开启自注册
self_registration = on# Token有效时间,默认30分钟
token_expiration = 30# 用户创建项目权限控制,默认是everyone(所有人),也可以设置为adminonly(只能管理员)
project_creation_restriction = everyone#Determine whether the job service should verify the ssl cert when it connects to a remote registry.
#Set this flag to off when the remote registry uses a self-signed or untrusted certificate.
verify_remote_cert = on
#************************END INITIAL PROPERTIES************************

启动 harbor,修改完配置文件后,在的当前目录执行./install.sh,Harbor服务就会根据当期目录下的docker-compose.yml开始下载依赖的镜像,检测并按照顺序依次启动各个服务。

启动完成后,我们访问刚设置的 hostname 即可,http://115.159.227.249/,默认是80端口,如果端口占用,我们可以去修改docker-compose.yml文件中,对应服务的端口映射。

登录 Web Harbor , 输入用户名 admin,默认密码(或已修改密码)登录系统。

我们可以看到系统各个模块如下:

  • 项目:新增/删除项目,查看镜像仓库,给项目添加成员、查看操作日志、复制项目等
  • 日志:仓库各个镜像create、push、pull等操作日志
  • 系统管理
    • 用户管理:新增/删除用户、设置管理员等
    • 复制管理:新增/删除从库目标、新建/删除/启停复制规则等
    • 配置管理:认证模式、复制、邮箱设置、系统设置等
  • 其他设置
    • 用户设置:修改用户名、邮箱、名称信息
    • 修改密码:修改用户密码

注意:非系统管理员用户登录,只能看到有权限的项目和日志,其他模块不可见。

我们要尝试下能不能把自己 Docker 里面的镜像 push 到 Harbor 的 library 里来(默认这个 library 项目是公开的,所有人都可以有读的权限,都不需要 docker login 进来,就可以拉取里面的镜像)。

注意:

为了后面留坑,我这里先 在自己的 docker.service 中添加仓库:(这是个坑,建议你先按照我说的做,不然下面可能会一直登录不上)

vim /usr/lib/systemd/system/docker.service里面的这行修改为:(其实就是添加 --insecure-registry 115.159.227.249 )
ExecStart=/usr/bin/dockerd --insecure-registry 115.159.227.249

添加完了后重新启动 docker:

systemctl daemon-reload && systemctl enable docker && systemctl start docker

启动 docker 服务:

service docker start

登录:(为了测试下能否登录成功)

admin登录
$ docker login 115.159.227.249
Username: admin
Password:
Login Succeeded

打 tag 并 push

docker tag ubuntu:15.10  115.159.227.249/library/ubuntu:15.10       //给我的镜像打个 tagdocker push  115.159.227.249/library/ubuntuThe push refers to a repository [115.159.227.249/library/ubuntu]
98d59071f692: Pushed
af288f00b8a7: Pushed
4b955941a4d0: Pushed
f121afdbbd5d: Pushed
15.10: digest: sha256:ec89c4a90f45f5e103860191890f48d8379e0504a2881ff706aef0768dc0321b size: 1150

上传完毕后,登录Web Harbor,选择项目 library,就可以看到我刚 push 的镜像了。

同理,你也可以测试下从 Harbor pull 镜像到你的 Docker 中去,这里就不继续演示了。

最后

转载请注明地址为:http://www.54tianzhisheng.cn/2017/11/26/Docker-harbor/

基于 Harbor 搭建 Docker 私有镜像仓库相关推荐

  1. 基于 registry 搭建 Docker 私有镜像仓库

    dockerhub: https://registry.hub.docker.com/_/registry 安装命令 docker run -p 5000:5000 -d -v /opt/regist ...

  2. 华为云ECS-CentOS8.2部署(Harbor)Docker私有镜像仓库

    华为云ECS-CentOS8.2部署(Harbor)Docker私有镜像仓库 1.背景 2.环境说明 3.在CentOs中安装所需要的软件包 4.部署Harbor 4.1.安装docker-compo ...

  3. 搭建Docker私有镜像仓库

    一.Docker镜像和容器的区别 Docker的整个生命周期由三部分组成:镜像(image)+容器(container)+仓库(repository) 容器等于镜像加上可读层,容器是由镜像实例化而来的 ...

  4. Docker 私有镜像仓库的搭建及认证

    转自乐字节 DockerHub 为我们提供了很多官方镜像和个人上传的镜像,我们可以下载机构或个人提供的镜像,也可以上传我们自己的本地镜像,但缺点是: 由于网络的原因,从 DockerHub 下载和上传 ...

  5. 使用Harbor配置Kubernetes私有镜像仓库

    2019独角兽企业重金招聘Python工程师标准>>> Harbor使用了基于角色的访问控制策略,当从Harbor中拉去镜像的时候,首先要进行身份认证,认证通过后才可以拉取镜像.在命 ...

  6. 【Docker】registry部署docker私有镜像仓库

    Docker Hub作为Docker默认官方公共镜像仓库,但是如果我们不想使用怎么办,第一我们可以替换默认镜像仓库为我们国内的一些镜像仓库,第二就是如我们自己搭建一个自己的私有镜像仓库,官方也提供do ...

  7. Docker私有镜像仓库是什么?

    Docker镜像仓库概述 镜像仓库作为Docker技术的核心组件之一,其主要作用就是负责镜像内容的存储和分发.Docker镜像仓库从使用范围来说分为"公有镜像仓库"和"私 ...

  8. 阿里云部署Docker私有镜像仓库

    一.访问阿里云容器镜像服务地址 地址:https://cr.console.aliyun.com/cn-beijing/instances 提示开通->设置密码(为Docker仓库密码) 二.选 ...

  9. Docker私有镜像仓库

    文章目录 Docker Registry Docker Private Registry 使用docker-distribution自建Registry 使用官方镜像自建Registry Harbor ...

最新文章

  1. c语言大项目经验,C语言该学的地方(项目经验)
  2. demo:a spreadsheet-like application
  3. 高级数据结构与算法 | 深度遍历搜索(DFS)与广度遍历搜索(BFS)
  4. Linux 字符设备驱动开发基础(一)—— 编写简单 LED 设备驱动
  5. [译]Kinect for Windows SDK开发入门(八):骨骼追踪进阶 上
  6. Matlab Tricks(二十五)—— plot 属性
  7. ini_set和require使用
  8. 2021泰迪杯数据分析技能赛B题解题思路分享
  9. 音视频开发入门基础及视频会议即时通讯开源技术选择
  10. gitlab备份库局域网中远程备份至另一台windows电脑
  11. 带t2芯片的mac装linux,制作macOS系统盘超级简单,以及T2芯片的安装方法
  12. ABT 共识社区北京聚会 共建去中心化生态 | ArcBlock 社区
  13. MS SQL Server 数据库连接字符串详解
  14. 一个在线测试正则表达式的网站推荐
  15. windows phone 数字拼图小游戏
  16. 正态性/方差齐性检验及stata实现
  17. YOLOv5实战中国交通标志识别(TT100K数据集)
  18. 拥有无数个智能摄像头,却还没让城市睁开双眼
  19. 京瓷m1025底灰_京瓷复印机打印有底灰
  20. 常用QQ还是得绑定手机号,开启QQ手机安全助手。

热门文章

  1. Thinkphp 树形菜单(基于zTree)简单好用
  2. Marathon Oil 通过使用 Liquid UI 简化 SAP PM,将生产力提高了 90%
  3. jquery unbind 事件
  4. 如何科学跑步 - 刨析
  5. mysql半同步和无损复制_mysql主从之半同步复制和lossless无损复制
  6. 实验六 Java异常处理与集合的使用
  7. 解析新浪微博的登录过程
  8. 五步搞定Android开发环境部署,架构师必备技能
  9. 时间流逝(flow)——概率题
  10. TEXlive+textmaker