Harbor 私有镜像仓库
harbor:
Harbor是构建企业级私有docker镜像的仓库的开源解决方案,它是Docker Registry的更高级封装,它除了提供友好的Web UI界面,角色和用户权限管理,用户操作审计等功能外,它还整合了K8s的插件(Add-ons)仓库,即Helm通过chart方式下载,管理,安装K8s插件,而chartmuseum可以提供存储chart数据的仓库【注:helm就相当于k8s的yum】。另外它还整合了两个开源的安全组件,一个是Notary,另一个是Clair,Notary类似于私有CA中心,而Clair则是容器安全扫描工具,它通过各大厂商提供的CVE漏洞库来获取最新漏洞信息,并扫描用户上传的容器是否存在已知的漏洞信息,这两个安全功能对于企业级私有仓库来说是非常具有意义的。
是VMWare公司提供的一个docker私有仓库构建程序,功能非常强大.
1. 支持多租户签名和认证
2. 支持安全扫描和风险分析
3. 这次日志审计
4. 基于角色的访问控制
5. 支持可扩展的API和GUI
6. Image replication between instances
部署:
安装环境:
centos 7.4 docker-ce docker-compose 可以参照安装docker-ce:https://www.runoob.com/docker/centos-docker-install.html
安装docker-compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose docker-compose --version
软件下载:(我下载的版本:harbor-offline-installer-v2.0.3.tgz)
https://github.com/goharbor/harbor/releases
配置docker镜像加速:(国内从 DockerHub 拉取镜像有时会遇到困难,此时可以配置镜像加速器)
vim /etc/docker/daemon.json
{"registry-mirrors":["https://09q5vwna.mirror.aliyuncs.com"]} {"registry-mirrors":["https://reg-mirror.qiniu.com/"]} {"registry-mirrors":["https://hub-mirror.c.163.com/"]} { "dns":[ "114.114.114.114", "8.8.8.8" ] }
可参照:https://www.runoob.com/docker/docker-mirror-acceleration.html
安装:
tar -xf harbor-offline-installer-v2.0.3.tgz cd harbor/ cp harbor.yml.tmpl harbor.yml vim harbor.yml hostname: 192.168.11.115 harbor_admin_password: 123@456
data_volume: /data
./install.sh
查看/data目录
[root@11_115_repository data]# ls ca_download database job_logs redis registry secret # 生成的文件目录
使用docker-compose查看
[root@11_115_repository soft]# cd harbor/ # 进入安装目录 [root@11_115_repository harbor]# ls common common.sh docker-compose.yml harbor.v2.0.3.tar.gz harbor.yml harbor.yml.tmpl install.sh LICENSE prepare [root@11_115_repository harbor]# [root@11_115_repository harbor]# [root@11_115_repository harbor]# [root@11_115_repository harbor]# docker-compose ps # 安装完成后,会自动生成下面的 Name Command State Ports --------------------------------------------------------------------------------------------- harbor-core /harbor/entrypoint.sh Up (healthy) harbor-db /docker-entrypoint.sh Up (healthy) 5432/tcp harbor-jobservice /harbor/entrypoint.sh Up (healthy) harbor-log /bin/sh -c /usr/local/bin/ ... Up (healthy) 127.0.0.1:1514->10514/tcp harbor-portal nginx -g daemon off; Up (healthy) 8080/tcp nginx nginx -g daemon off; Up (healthy) 0.0.0.0:80->8080/tcp redis redis-server /etc/redis.conf Up (healthy) 6379/tcp registry /home/harbor/entrypoint.sh Up (healthy) 5000/tcp registryctl /home/harbor/start.sh Exit 137
启动所有服务
[root@11_115_repository harbor]# docker-compose up -d
如果遇到报错:ERROR:root:Error: The protocol is https but attribute ssl_cert is not set。 原因是harbor.yml中默认是配置https的端口及证书路径的。
最快的解决办法是把这些配置都注释掉,当然也可以申请证书配置好。 # https related config # https: # https port for harbor, default is 443 # port: 443 # The path of cert and key files for nginx # certificate: /your/certificate/path # private_key: /your/private/key/path
在浏览器中输入:http://192.168.11.115/ 账号:admin 密码:harbor.yml配置文件中
测试上传
登陆web页面------------>新建项目------------>分配空间
docker机器
[root@localhost ~]# cat /etc/docker/daemon.json { "registry-mirrors": ["https://09q5vwna.mirror.aliyuncs.com"], # 配置加速地址 "insecure-registries": ["192.168.11.115:80"] # 配置私有仓库地址 }
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker.service
docker机器登陆私有仓库
[root@localhost ~]# docker login 192.168.11.115:80 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
在项目中标记镜像:
docker tag dugushubo/centos:latest 192.168.11.115:80/football/dugushubo:v1.1 # 标记当前docker镜像
推送镜像到当前项目:
[root@localhost ~]# docker push 192.168.11.115:80/football/dugushubo The push refers to repository [192.168.11.115:80/football/dugushubo] eb29745b8228: Pushed v1.1: digest: sha256:c57152daba574c8d142a1775adf9f01134ebab20b01f67be61627d2155aebe7c size: 529
在web页面查看已上传的镜像:
拉取镜像
[root@localhost ~]# docker pull 192.168.11.115:80/football/dugushubo:v1.1 v1.1: Pulling from football/dugushubo Digest: sha256:c57152daba574c8d142a1775adf9f01134ebab20b01f67be61627d2155aebe7c Status: Downloaded newer image for 192.168.11.115:80/football/dugushubo:v1.1 192.168.11.115:80/football/dugushubo:v1.1
查看镜像
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.11.115:80/football/dugushubo v1.1 dd255aac7d63 3 months ago 215MB
下载数会改变