当前位置: 首页 > news >正文

Jenkins (七) - Docker Harbor

Jenkins (七) - Docker Harbor

Harbor

下载 Harbor v2.10.1 离线安装包

解压

解压到 /home/tester/app/

$ ls -l
total 633784
-rw-r--r-- 1 tester tester     11347 Mar 13 18:01 LICENSE
drwxr-xr-x 3 root   root        4096 Apr  7 11:42 common
-rw-r--r-- 1 tester tester      3643 Mar 13 18:01 common.sh
-rw-r--r-- 1 root   root        5845 Apr  7 11:54 docker-compose.yml
-rw-r--r-- 1 tester tester 648902394 Mar 13 18:01 harbor.v2.10.1.tar.gz
-rw-r--r-- 1 tester tester     14013 Apr  7 11:36 harbor.yml.tmpl
-rwxr-xr-x 1 tester tester      1975 Mar 13 18:01 install.sh
-rwxr-xr-x 1 tester tester      1882 Mar 13 18:01 prepare

配置Harbor

  • 生成 harbor.yml
$ cp harbor.yml.tmpl harbor.yml
  • 修改 harbor.yml 中的 hostnamehttp.port, hostname 设置为本机IP。
# ...
# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
#hostname: reg.mydomain.com
hostname: 192.168.56.102
# http related config
http:# port for http, default is 80. If https enabled, this port will redirect to https port
#  port: 80port: 5100
# 用不上https则,注释https,否则会安装失败 - ERROR:root:Error: The protocol is https but attribute ssl_cert is not set
# 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# enable strong ssl ciphers (default: false)# strong_ssl_ciphers: false
...

安装Harbor

  • 非root用户使用sudo安装 sudo ./install.sh
$ sudo ./install.sh [Step 0]: checking if docker is installed ...Note: docker version: 24.0.7[Step 1]: checking docker-compose is installed ...Note: Docker Compose version v2.21.0[Step 2]: loading Harbor images ......[Step 5]: starting Harbor ...
[+] Running 10/10✔ Network harbor_harbor        Created                                                                                    0.2s ✔ Container harbor-log         Started                                                                                    0.2s ✔ Container registry           Started                                                                                    0.2s ✔ Container registryctl        Started                                                                                    0.2s ✔ Container harbor-db          Started                                                                                    0.2s ✔ Container redis              Started                                                                                    0.2s ✔ Container harbor-portal      Started                                                                                    0.3s ✔ Container harbor-core        Started                                                                                    0.1s ✔ Container harbor-jobservice  Started                                                                                    0.1s ✔ Container nginx              Started                                                                                    0.2s 
✔ ----Harbor has been installed and started successfully.---
$ cat << EOF | sudo tee /etc/systemd/system/harbor.service
[Unit]
Description=Harbor
After=docker.service systemd-networkd.service systemd-resolved.service
Requires=docker.service
Documentation=http://github.com/vmware/harbor[Service]
Type=simple
Restart=on-failure
RestartSec=5
ExecStart=docker compose --file /home/tester/app/harbor/docker-compose.yml up
ExecStop=docker compose --file /home/tester/app/harbor/docker-compose.yml down[Install]EOF

验证Harbor

http://192.168.56.102:5100
在这里插入图片描述
默认账号密码 admin/Harbor12345 可以从 harbor.yml文件中找到

# The initial password of Harbor admin
# It only works in first time to install harbor
# Remember Change the admin password from UI after launching Harbor.
harbor_admin_password: Harbor12345

在这里插入图片描述

新建Harbor用户

  • Users -> New User
    username: tester
    password: Tester123456
    在这里插入图片描述
    在这里插入图片描述
  • 设为管理员
    在这里插入图片描述

远程命令行登录

$ sudo docker login 192.168.56.102:5100
Username: tester
Password: 
WARNING! Your password will be stored unencrypted in /home/tester/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded

验证本地推送

新建一个自定义的工程
ProjectName: p_pub,
Access Level: Public

  • Public: 所有用户对于公开项目都有读权限,此种方式可以仓库分享给他人。
  • Private: 私有项目只能被有特定用户权限的人去访问。
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    PUSH COMMAND 给出了打包推送的命令
    在这里插入图片描述
    docker tag SOURCE_IMAGE[:TAG] 192.168.56.102:5100/p_pub/REPOSITORY[:TAG]
    docker push 192.168.56.102:5100/p_pub/REPOSITORY[:TAG]

给用户tester设置可以推送,拉取p_pub仓库权限在这里插入图片描述
官网的Members图描述了各个Role能做什么
在这里插入图片描述

在这里插入图片描述

$ sudo docker pull hello-world
[sudo] password for tester: 
Using default tag: latest
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete 
Digest: sha256:53641cd209a4fecfc68e21a99871ce8c6920b2e7502df0a20671c6fccc73a7c6
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest$ sudo docker images
REPOSITORY                              TAG       IMAGE ID       CREATED         SIZE
192.168.56.102:5100/p_pub/hello-world   v1.0      d2c94e258dcb   11 months ago   13.3kB
hello-world                             latest    d2c94e258dcb   11 months ago   13.3kB
# 给镜像打标,后续推入私服
$ sudo docker tag hello-world:latest 192.168.56.102/p_pub/hello-world:v1.0
# 推送入私服
$ sudo docker push 192.168.56.102:5100/p_pub/hello-world:v1.0
The push refers to repository [192.168.56.102:5100/p_pub/hello-world]
ac28800ec8bb: Pushed 
v1.0: digest: sha256:d37ada95d47ad12224c205a938129df7a3e52345828b4fa27b03a98825d1e2e7 size: 524

在这里插入图片描述
在这里插入图片描述

验证本地拉取

# 删除已有的镜像
$ sudo docker rmi 192.168.56.102:5100/p_pub/hello-world:v1.0
Untagged: 192.168.56.102:5100/p_pub/hello-world:v1.0
Untagged: 192.168.56.102:5100/p_pub/hello-world@sha256:d37ada95d47ad12224c205a938129df7a3e52345828b4fa27b03a98825d1e2e7
# 查看已删除的镜像
$ sudo docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    d2c94e258dcb   11 months ago   13.3kB
# 从服务器上拉取
$ sudo pull 192.168.56.102:5100/p_pub/hello-world:v1.0
sudo: pull: command not found
$ sudo docker pull 192.168.56.102:5100/p_pub/hello-world:v1.0
v1.0: Pulling from p_pub/hello-world
Digest: sha256:d37ada95d47ad12224c205a938129df7a3e52345828b4fa27b03a98825d1e2e7
Status: Downloaded newer image for 192.168.56.102:5100/p_pub/hello-world:v1.0
192.168.56.102:5100/p_pub/hello-world:v1.0
# 查看已拉取的镜像
$ sudo docker images
REPOSITORY                              TAG       IMAGE ID       CREATED         SIZE
192.168.56.102:5100/p_pub/hello-world   v1.0      d2c94e258dcb   11 months ago   13.3kB
hello-world                             latest    d2c94e258dcb   11 months ago   13.3kB

安装错误提示

  1. ERROR:root:Error: The protocol is https but attribute ssl_cert is not set
    解决:禁用 harbor.yml https 相关配置
$ ./install.sh [Step 0]: checking if docker is installed ...Note: docker version: 24.0.7[Step 1]: checking docker-compose is installed ...Note: Docker Compose version v2.21.0[Step 2]: loading Harbor images ......ace40209f742: Loading layer [==================================================>]  227.3MB/227.3MB
Loaded image: goharbor/trivy-adapter-photon:v2.10.1[Step 3]: preparing environment ...[Step 4]: preparing harbor configs ...
prepare base dir is set to /home/tester/app/harbor
Error happened in config validation...
ERROR:root:Error: The protocol is https but attribute ssl_cert is not set
  1. harbor/common/config/registryctl/env: permission denied
    解决:提升账户权限或者使用root用户
[Step 4]: `preparing harbor configs ...`
prepare base dir is set to /home/tester/app/harbor
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
Generated and saved secret to file: /data/secret/keys/secretkey
Successfully called func: create_root_cert
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dirNote: stopping existing Harbor instance ...
Failed to load /home/tester/app/harbor/common/config/registryctl/env: open /home/tester/app/harbor/common/config/registryctl/env: permission denied
  1. 本地docker 登入Harbor失败
    Error response from daemon: Get “https://192.168.56.102/v2/”: dial tcp 192.168.56.102:443: connect: connection
tester@tester:~/app/harbor$ docker login 192.168.56.102
Username: tester
Password: 
Error response from daemon: Get "https://192.168.56.102/v2/": dial tcp 192.168.56.102:443: connect: connection refused
$ cat /etc/docker/daemon.json
cat: /etc/docker/daemon.json: No such file or directory
$ sudo vim /etc/docker/daemon.json
[sudo] password for tester: 
$ sudo service docker restart
$ cat /etc/docker/daemon.json 
{"registry-mirrors": ["https://hub-mirror.c.163.com"],"insecure-registries": ["192.168.56.102:5100"]
}
$ sudo docker compose down
[+] Running 10/10✔ Container harbor-jobservice  Removed                                                                                    0.5s ✔ Container registryctl        Removed                                                                                    0.5s ✔ Container nginx              Removed                                                                                    0.6s ✔ Container harbor-core        Removed                                                                                    0.4s ✔ Container harbor-portal      Removed                                                                                    0.4s ✔ Container harbor-db          Removed                                                                                    0.7s ✔ Container redis              Removed                                                                                    0.6s ✔ Container registry           Removed                                                                                    0.5s ✔ Container harbor-log         Removed                                                                                   10.4s ✔ Network harbor_harbor        Removed                                                                                    0.3s 
$ sudo docker compose up -d
[+] Running 10/10✔ Network harbor_harbor        Created                                                                                    0.2s ✔ Container harbor-log         Started                                                                                    0.1s ✔ Container registry           Started                                                                                    0.2s ✔ Container registryctl        Started                                                                                    0.2s ✔ Container harbor-db          Started                                                                                    0.2s ✔ Container harbor-portal      Started                                                                                    0.2s ✔ Container redis              Started                                                                                    0.2s ✔ Container harbor-core        Started                                                                                    0.1s ✔ Container nginx              Started                                                                                    0.1s ✔ Container harbor-jobservice  Started                                                                                    0.1s
$ docker login 192.168.56.102:5100
Username: admin
Password: 
WARNING! Your password will be stored unencrypted in /home/tester/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded
  1. 网段其他机器访问 dial unix /var/run/docker.sock: connect: permission denied
    解决: 使用root用户或者提升当前用户权限 sudo docker login 192.168.56.102:5100
$ docker login 192.168.56.102:5100
Username: tester
Password: 
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/auth": dial unix /var/run/docker.sock: connect: permission denied$ sudo docker login 192.168.56.102:5100
Username: tester
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-storeLogin Succeeded

HTTPS 证书配置

如果使用自签名的https证书,仍然会提示证书不受信任的问题。需要将自签名的ca证书发送到所有的docker客户端的指定目录。
关于使用自签名证书配置harbor的具体过程可以参考: https://goharbor.io/docs/2.10.0/install-config/configure-https/

相关文章:

  • 三维表面轮廓仪的维护保养是确保其长期稳定运行的关键
  • Java操作数据库,JDBC
  • 【C++】vector容器实现
  • sqli-labs第十八关——POST-UA注入
  • 【题解-洛谷】B4302 [蓝桥杯青少年组省赛 2024] 出现奇数次的数
  • 振动分析 - 献个宝
  • Java垃圾回收与JIT编译优化
  • msdn怎么下载win10专业版_msdn上下载win10专业版及安装方法
  • 直播美颜SDK技术解析:滤镜渲染与动态贴纸引擎融合的底层实现
  • Go语言内存共享与扩容机制 -《Go语言实战指南》
  • 5月21日
  • AI驱动新增长:亚马逊Rufus广告点击率提升300%的奥秘
  • 回溯法求解N皇后问题
  • 【C++ 真题】P5736 【深基7.例2】质数筛
  • 【笔记】PyCharm 中创建Poetry解释器
  • PyTorch学习之:torch.gather是什么?
  • MBSS-T1:基于模型的特定受试者自监督运动校正方法用于鲁棒心脏 T1 mapping|文献速递-深度学习医疗AI最新文献
  • InetAddress 类详解
  • 第一章 Proteus中Arduino的可视化程序
  • 宁夏建设工程专业技术职称评审条件
  • 简易网站开发时长/好看的网站ui
  • 新疆网站开发价格/合肥seo建站
  • 长春高铁站/app开发自学
  • 成都现在的疫情情况怎么样/网站seo如何做好优化
  • wordpress图片上浮特效/seo还能赚钱吗