theboyaply

学,就硬学!

  • Home
  • Archives
  • Java
  • Maven
  • Docker
  • Kubernetes
  • JavaScript
  • ES6
  • Vue
  • 踩坑记录
  • noted

  • 搜索
element ui vue wsimport webservice npm mysql redis node nginx nfs ftp es6 开发工具 vscode 前端 javascript springboot 常见问题 tomcat oracle jenkins maven k8s Linux gitlab docker java

Docker Harbor仓库

发表于 2020-03-12 | 分类于 Docker | 0 | 阅读次数 403
  • Harbor 简介
  • 下载安装
  • 推送镜像

Harbor 简介

Harbor 是一个用于存储和分发 Docker 镜像的企业级 Registry 服务器,通过添加一些企业必需的功能特性,例如安全、标识和管理等,扩展了开源 Docker Distribution 。作为一个企业级私有 Registry 服务器, Harbor 提供了更好的性能和安全。提升用户使用 Registry 构建和运行环境传输镜像的效率。 Harbor 支持安装在多个 Registry 节点的镜像资源复制,镜像全部保存在私有 Registry 中, 确保数据和知识产权在公司内部网络中管控。另外, Harbor 也提供了高级的安全特性,诸如用户管理,访问控制和活动审计等。

官方文档:https://goharbor.io/docs/
Github用户手册:https://github.com/goharbor/harbor/blob/master/docs/user_guide.md

Github releases:https://github.com/goharbor/harbor/releases

下载安装

Harbor 有离线安装和在线安装,其需要的文件都可以在 https://github.com/goharbor/harbor/releases 上下载。我们这里选择离线安装。

下载离线安装压缩包:

wget -P /dockerDir/harbor https://github.com/goharbor/harbor/releases/download/v1.10.1/harbor-offline-installer-v1.10.1.tgz

其中 -P 参数为指定下载到哪个目录。

PS:因为下载较慢,所以下面使用的是以前下载好的 v1.1.2 的版本。

解压并修改配置文件:

# 解压
tar -xzvf harbor-offline-installer-v1.1.2.tgz

# 解压完成后进入 harbor 目录
cd harbor

# 编辑 harbor 目录下的配置文件 harbor.cfg(新版本的叫 harbor.conf ???)
vim harbor.cfg

以下是 harbor.cfg 部分参数说明:

# 访问 harbor 的地址,可以是 ip 或域名,但不能是 localhost 和 127.0.0.1
hostname = reg.mydomain.com

# 访问协议,默认是http,也可以设置https,如果设置https,则nginx ssl需要设置on
ui_url_protocol = http

# mysql数据库root用户默认密码root123,实际使用时修改它
db_password = root123

# 在页面登录时管理员账户 admin 的默认密码
harbor_admin_password = Harbor12345

# 认证方式,这里支持多种认证方式,如LADP、本次存储、数据库认证。默认是db_auth,mysql数据库认证
auth_mode = db_auth

# 是否开启自注册,on 表示可以注册用户
self_registration = on

# Token有效时间,默认30分钟
token_expiration = 30

# 用户创建项目权限控制,默认是everyone(所有人),也可以设置为adminonly(只能管理员)
project_creation_restriction = everyone

配置文件中还可以设置 邮件 和 LADP 等参数,若实际操作时需要用到,可自行配置。

然后执行当前目录的 install.sh,harbor 会根据当前目录下的docker-compose.yml下载依赖的镜像,检测并按照顺序依次启动各个服务:

./install.sh

# 部分日志
[Step 4]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-db          ... done
Creating registry           ... done
Creating harbor-adminserver ... done
Creating harbor-ui          ... done
Creating harbor-jobservice  ... done
Creating nginx              ... done

✔ ----Harbor has been installed and started successfully.----

Now you should be able to visit the admin portal at http://192.168.19.115. 
For more details, please visit https://github.com/vmware/harbor .

安装完成之后就可以访问 harbor 了,同时还可以使用 docker ps -a 查看 harbor 运行了哪些容器。

进入 harbor 后会看见一个名称为 library 的项目,这是默认项目且访问级别为公开(表示任何人可读,即任何人都可以下载该项目中的镜像)。

我们还可以在 harbor 中修改系统配置,具体的可配置项请在登录 harbor 后自行查看。

推送镜像

harbor 搭建好了之后,想要推送镜像到仓库,还需要配置 docker 信任仓库地址。

两种方式:

  • 修改 /etc/docker/daemon.json 文件,多个地址使用逗号隔开。

    下面的 IP 地址,我在末尾加上 :80,使用 docker login 不能正常登录 harbor,去掉 :80 就行了,不知道是啥原因。

    {
      "insecure-registries": [
        "192.168.19.115"
      ]
    }
    
  • 修改 /usr/lib/systemd/system/docker.service 文件,在 ExecStart属性后面追加 --insecure-registry=192.168.19.115

修改完成后重启 docker 服务:

sudo systemctl daemon-reload
sudo systemctl restart docker

注意,harbor 相关容器可能不是自动重启,需要在 docker 重启完成之后手动启动。

进入 harbor 页面并创建一个名为 tom 的私有项目,然后推送一个 nginx 镜像上去。其格式为:

docker tag local-image:tag harbor-ip/project-name/image-name:tag

演示:

# 登录 harbor,-uadmin 表示用户名是admin, -pHarbor12345 表示密码是Harbor12345
[root@localhost ~]# docker login -uadmin -pHarbor12345 192.168.19.115
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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

# 打tag
[root@localhost system]# docker tag nginx 192.168.19.115/tom/nginx:v1

# 推送镜像
[root@localhost system]# docker push 192.168.19.115/tom/nginx:v1
The push refers to repository [192.168.19.115/tom/nginx]
55a77731ed26: Pushed 
71f2244bc14d: Pushed 
f2cb0ecef392: Pushed 
v1: digest: sha256:3936fb3946790d711a68c58be93628e43cbca72439079e16d154b5db216b58da size: 948

# 删除本地 192.168.19.115/tom/nginx:v1 镜像
docker rmi 192.168.19.115/tom/nginx:v1

# pull 仓库镜像
docker pull 192.168.19.115/tom/nginx:v1

如果不进行登录,是无法 pull 和 push 的,如:

[root@localhost system]# docker logout 192.168.19.115
Removing login credentials for 192.168.19.115

[root@localhost system]# docker pull 192.168.19.115/tom/nginx:v1
Error response from daemon: pull access denied for 192.168.19.115/tom/nginx, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

[root@localhost system]# docker push 192.168.19.115/tom/nginx:v1
The push refers to repository [192.168.19.115/tom/nginx]
55a77731ed26: Preparing 
71f2244bc14d: Preparing 
f2cb0ecef392: Preparing 
denied: requested access to the resource is denied

-- end --

# docker
Docker 私有镜像仓库高级配置
docker-compose 介绍
  • 文章目录
  • 站点概览
theboyaply

theboyaply

好记性不如烂笔头

184 日志
13 分类
27 标签
Github E-mail
Creative Commons
0%
© 2019 — 2023 theboyaply
由 Halo 强力驱动
|
主题 - NexT.Gemini
湘ICP备19009291号

湘公网安备 43312402001034号