Docker私有仓库Harbor部署与使用
Posted zhaomeng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker私有仓库Harbor部署与使用相关的知识,希望对你有一定的参考价值。
一、harbor介绍
Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器。
由下面几个组件组成:
- proxy:nginx前端代理,主要是分发前端页面ui访问和镜像上传和下载流量
- registry:镜像仓库,负责存储镜像文件
- 核心服务:提供web ui,数据库,token认证,webhook等功能
- 日志服务
- database:用来存储核心服务的一些数据
因为是vmware出品的,所以支持下面几种部署方式
- 在线安装
- 离线安装
- ova安装,这个直接在vcenter上导入就可以了
官方最小配置
- 2个cpu
- 4g内存
- 40g硬盘,因为是存储镜像的所以推荐硬盘大点
二、搭建过程
Install Docker CE
[email protected]:~# apt-get update [email protected]:~# apt-get install apt-transport-https ca-certificates software-properties-common curl [email protected]:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg |sudo apt-key add - [email protected]:~# apt-key fingerprint 0EBFCD88 [email protected]:~# add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" [email protected]:~# apt-get update [email protected]:~# apt-get install docker-ce
Install Docker-compose
[email protected]:~# curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose [email protected]:~# chmod +x /usr/local/bin/docker-compose #查看版本 [email protected]:~# docker --version Docker version 18.09.0, build 4d60db4 [email protected]:~# docker-compose --version docker-compose version 1.22.0, build f46880fe
Install harbor
[email protected]:~# wget https://storage.googleapis.com/harbor-releases/release-1.6.0/harbor-offline-installer-v1.6.0.tgz [email protected]:~# tar -zxvf harbor-offline-installer-v1.6.0.tgz #编辑配置文件 [email protected]:~# cd harbor/ [email protected]:~/harbor# vim harbor.cfg hostname = 114.112.34.27 project_creation_restriction = adminonly #Python环境 [email protected]:~/harbor# apt-get install python [email protected]:~/harbor# export LC_ALL=C [email protected]:~/harbor# ln -s /usr/bin/python3 /usr/bin/python #安装服务 [email protected]:~/harbor# ./install.sh
看到以下内容,说明安装成功:
启动服务:
[email protected]:~/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 [email protected]:~/harbor# docker-compose ps Name Command State Ports ------------------------------------------------------------------------------------------------------------------------------------- harbor-adminserver /harbor/start.sh Up (healthy) harbor-db /entrypoint.sh postgres Up (healthy) 5432/tcp harbor-jobservice /harbor/start.sh Up harbor-log /bin/sh -c /usr/local/bin/ ... Up (healthy) 127.0.0.1:1514->10514/tcp harbor-ui /harbor/start.sh Up (healthy) 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 redis docker-entrypoint.sh redis ... Up 6379/tcp registry /entrypoint.sh /etc/regist ... Up (healthy) 5000/t
配置HTTPS
##如果不做HTTPS,只需将hostname设置为IP,protocol改为HTTP即可,也不必生成CA [email protected]:~/harbor# vi harbor.cfg
#创建目录 [email protected]:~/harbor# mkdir -p /data/cert/ #生成ca证书和签名 [email protected]:~/harbor# openssl genrsa -out /data/cert/ca.key 2048 [email protected]:~/harbor# openssl req -x509 -new -nodes -key /data/cert/ca.key -subj "/CN=test.harbor.com" -days 5000 -out /data/cert/ca.crt #启动服务 [email protected]:~/harbor# ./prepare [email protected]:~/harbor# docker-compose down [email protected]:~/harbor# docker-compose up -d
测试
修改本地host,添加一行内容 114.112.34.27 test.harbor.com 在浏览器中访问 http://test.harbor.com/ 默认用户名/密码:admin/Harbor12345
登录成功后会看到如下页面:
添加项目:
进入此项目,可以看到推送镜像的命令:
删除项目:
确认项目不再使用时,选中项目,点击删除
点击删除:
在服务器进行测试
修改本地Docker默认仓库,指向Harbor
[email protected]:/data/cert# cp ca.crt /usr/local/share/ca-certificates/ [email protected]:/data/cert# update-ca-certificates #修改docker配置文件,指向Harbor [email protected]:~/harbor# vi /etc/default/docker #添加一行内容 DOCKER_OPTS="--insecure-registry=test.harbor.com" #重启docker服务 [email protected]:~# service docker restart
将本地Ubuntu镜像上传至Harbor
#将本地镜像打一个tag [email protected]:~# docker tag ubuntu:16.04 test.harbor.com/paas/ubuntu:v1.0 #推送到Harbor上 [email protected]:~/harbor# docker push test.harbor.com/paas/ubuntu:v1.0
下载Harbor镜像至本地
[email protected]:~/harbor# docker pull test.harbor.com/paas/ubuntu:v1.0 v1.0: Pulling from paas/ubuntu Digest: sha256:078d30763ae6697b7d55e49f4cb9e61407abd2137cafb5625f131aa47c1a47af Status: Downloaded newer image for test.harbor.com/paas/ubuntu:v1.0
以上是关于Docker私有仓库Harbor部署与使用的主要内容,如果未能解决你的问题,请参考以下文章