Docker已经上市不少年,不是什么新鲜事物了,不少企业或者开发同窗之前也很少很多有所接触,可是有实操经验的人很少,本系列教程主要偏重实战,尽可能讲干货,会根据本人理解去作阐述,具体官方概念能够查阅官方教程,由于本系列教程对前一章节有必定依赖,建议先学习前面章节内容。html
本系列教程导航:
Docker深刻浅出系列 | 容器初体验
Docker深刻浅出系列 | Image实战演练
Docker深刻浅出系列 | 单节点多容器网络通讯
Docker深刻浅出系列 | 容器数据持久化
Docker深刻浅出系列 | 单机Nginx+Springboot实战
Docker深刻浅出系列 | Docker Compose多容器实战node
教程目的:linux
官方概念: Harbor是一个开放源代码容器映像镜像表,可经过基于角色的访问控制来保护镜像,扫描镜像中的漏洞并将镜像签名为受信任。 做为CNCF孵化项目,Harbor提供合规性,性能和互操做性,以帮助您跨Kubernetes和Docker等云原生计算平台持续,安全地管理镜像。nginx
简单来讲,Harbor就是一个开源的镜像管理仓库,相似Github同样,可让咱们存放一些镜像文件git
更多详细内容,能够查看Harbor 官方文档github
有动手跟着我前面教程练习的同窗应该都有感觉,以前的Springboot项目每次都须要在服务器建立镜像,当我有多台服务器须要用到这个镜像,我还得重复在每台服务器上建立一次,那有没有一个中间存储服务帮咱们管理这些镜像,让全部的服务器能够共享这个镜像文件呢?Harbor的做用就是帮咱们管理镜像,采用分布式架构,让咱们能够在任意服务器拉去咱们构建好的镜像文件。而后又会有人问咱们不是已经有docker hub
或者 docker hub
这些远程仓库了吗?确实,可是当咱们须要搭建一些私有镜像仓库,不想把公司项目对外公开的时候,Harbor就颇有用了,就像不少公司也会在本身公司搭建私有的nexus服务器来管理公司内部的应用package。
redis
到github选择一个harbor
release版本下载
https://github.com/goharbor/harbor/releases
docker
上传到你的linux服务器,我这里沿用上一章建立的manager节点json
[root@manager-node harbor]# ls common.sh harbor.yml LICENSE harbor.v1.10.1.tar.gz install.sh prepare
上面是harbor应用解压后的文件浏览器
修改harbor配置文件
harbor.yml
#设置域名 hostname: 192.168.101.11 #设置http参数 # http related config http: # port for http, default is 80. If https enabled, this port will redirect to https port port: 8090 #设置管理员密码 harbor_admin_password: evan123 #屏蔽https #https: # https port for harbor, default is 443 # port: 443
上面修改了hostname为我虚拟机的ip,端口把默认80
端口替换成8090
,而且修改了管理员密码为evan123
。须要注意,我这里屏蔽了https
,若是你们须要开启https
,须要配置证书和key到指定位置
Docker默认是不支持http访问注册表,不然后面使用docker去访问harbor服务,会报以下错误:
http: server gave HTTP response to HTTPS client
这里须要先修改下/etc/docker/daemon.json
配置,加入如下配置
{ "insecure-registries" : ["192.168.101.11:8090"] }
重启docker服务
systemctl restart docker
假如没有Docker
环境,harbor
会启动报错
[root@manager-node harbor]# sh install.sh [Step 0]: checking if docker is installed ... Note: docker version: 19.03.7 [Step 1]: checking docker-compose is installed ... Note: docker-compose version: 1.25.0 [Step 2]: loading Harbor images ... Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
须要先安装Docker
和docker-compose
组件,这里就很少说了,你们能够参考前面章节的安装教程
当启动Docker后,执行install.sh
会自动完成安装
[root@manager-node harbor]# sh install.sh ... Creating network "harbor_harbor" with the default driver Creating harbor-log ... done Creating harbor-portal ... done Creating registry ... done Creating redis ... done Creating harbor-db ... done Creating registryctl ... done Creating harbor-core ... done Creating nginx ... done Creating harbor-jobservice ... done ✔ ----Harbor has been installed and started successfully.----
上面显示已经安装成功了
在浏览器输入上面咱们配置的ip和端口192.168.101.11:8090
,就会看到harbor
登录页面
这里使用咱们上面的定义的密码登录
admin
evan123
点击New
会进入项目建立对话框,这里填入项目名称便可,这里的访问级别我选择public
在使用Harbor以前,要在docker环境登录Harbor服务
[root@manager-node harbor]# docker login 192.168.101.11:8090 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
[root@manager-node credit-facility]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE credit-facility-image latest 28948b936fac 2 days ago 130MB
credit-facility-image
打个标签,新标签为credit-facility:1.0
docker tag credit-facility-image:latest credit-facility:1.0
credit-facility
进行发布[root@manager-node harbor]# docker push 192.168.101.11:8090/credit-facility/credit-facility-image The push refers to repository [192.168.101.11:8090/credit-facility/credit-facility-image] 21f243c9904f: Pushed edd61588d126: Pushed 9b9b7f3d56a0: Pushed f1b5933fe4b5: Pushed latest: digest: sha256:86a6289143d0a8a4cc94880b79af36416d07688585f8bb1b09fd4d50cd166f46 size: 1159
从上面显示结果能够看到,咱们已经成功上传镜像到Harbor仓库了
[root@manager-node harbor]# docker image rm 192.168.101.11:8090/credit-facility/credit-facility-image:latest Untagged: 192.168.101.11:8090/credit-facility/credit-facility-image:latest Untagged: 192.168.101.11:8090/credit-facility/credit-facility-image@sha256:86a6289143d0a8a4cc94880b79af36416d07688585f8bb1b09fd4d50cd166f46
[root@manager-node harbor]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE
如今本地已经没有任何镜像
3.从Harbor仓库拉去镜像
[root@manager-node harbor]# docker pull 192.168.101.11:8090/credit-facility/credit-facility-image:latest latest: Pulling from credit-facility/credit-facility-image Digest: sha256:86a6289143d0a8a4cc94880b79af36416d07688585f8bb1b09fd4d50cd166f46 Status: Downloaded newer image for 192.168.101.11:8090/credit-facility/credit-facility-image:latest 192.168.101.11:8090/credit-facility/credit-facility-image:latest
镜像已经拉取成功
4.在查看本地镜像列表验证下
[root@manager-node harbor]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.101.11:8090/credit-facility/credit-facility-image latest 28948b936fac 2 days ag
咱们的镜像已经成功安装到本地了,这样即使咱们之后换了一台服务器,也能够随时从Harbor仓库拉取镜像,不须要依赖本地服务器