Docker搭建私有仓库harbor(docker 镜像仓库搭建)

鼠扑  金牌会员 | 2024-7-26 18:16:26 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 577|帖子 577|积分 1731


  • Harbor介绍
   Docker容器应用的开发和运行离不开可靠的镜像管理,虽然Docker官方也提供了公共的镜像仓库,但是从安全和效率等方面考虑,部署我们私有环境内的Registry也是非常必要的。Harbor是由VMware公司开源的企业级的Docker
Registry管理项目,它包括权限管理(RBAC)、LDAP、日志审核、管理界面、自我注册、镜像复制和中文支持等功能。
官网地址:https://github.com/goharbor/harbor
  Docker Harbor是一个企业级的Docker Registry服务,旨在提供安全、可靠的镜像存储和管明白决方案。以下是Docker
Harbor的一些关键特点:
  

  • 私有Registry:Docker Harbor允许用户搭建私有的Docker Registry,使得企业可以在自己的内部网络中安全地存储和管理Docker镜像。
  • 安全性:Docker Harbor提供了访问控制、用户和团队管理功能,以确保镜像的安全性。它支持用户身份验证、权限控制、安全扫描等功能,帮助用户掩护他们的容器镜像不受未经授权的访问。
  • 可扩展性:Docker Harbor支持集群部署,可以轻松地扩展以应对大规模的容器镜像存储需求。
  • 镜像复制和同步:Docker Harbor允许用户在差别的Registry之间复制和同步镜像,方便用户在多个部署环境之间共享和管理镜像。
  • 审计和日志记录:Docker Harbor提供审计和日志记录功能,记任命户对镜像的利用,以帮助用户跟踪镜像的变更历史。 总的来说,Docker Harbor是一个功能强盛的企业级Docker
    Registry服务,为用户提供了安全、可靠的方式来管理和存储Docker镜像。
  

  • 所必要的安装包
   链接:https://pan.baidu.com/s/1rN25l72i6W36ANAOqxcc_w 提取码:1021
  

  • 为harbor签发证书
  1. [root@harbor ~]# hostnamectl set-hostname harbor && /bin/bash
  2. [root@harbor ~]# mkdir /data/ssl -p
  3. [root@harbor ~]# cd /data/ssl/
  4. #生成ca证书
  5. #生成一个3072位的key,也就是私钥
  6. [root@harbor ssl]# openssl genrsa -out ca.key 3072
  7. Generating RSA private key, 3072 bit long modulus
  8. ...........++
  9. .............++
  10. e is 65537 (0x10001)
  11. #生成一个数字证书ca.pem,3650表示证书的有效时间是3年,按箭头提示填写即可,没有箭头标注的为空:
  12. [root@harbor ssl]# openssl req -new -x509 -days 3650 -key ca.key -out ca.pem
  13. You are about to be asked to enter information that will be incorporated
  14. into your certificate request.
  15. What you are about to enter is what is called a Distinguished Name or a DN.
  16. There are quite a few fields but you can leave some blank
  17. For some fields there will be a default value,
  18. If you enter '.', the field will be left blank.
  19. -----
  20. Country Name (2 letter code) [XX]:CH
  21. State or Province Name (full name) []:BJ
  22. Locality Name (eg, city) [Default City]:BJ
  23. Organization Name (eg, company) [Default Company Ltd]:BJ
  24. Organizational Unit Name (eg, section) []:BJ
  25. Common Name (eg, your name or your server's hostname) []:CHONG
  26. Email Address []:123@163.com
  27. #生成域名的证书
  28. #生成一个3072位的key,也就是私钥
  29. [root@harbor ssl]# openssl genrsa -out harbor.key  3072
  30. Generating RSA private key, 3072 bit long modulus
  31. .++
  32. ..........................................................++
  33. e is 65537 (0x10001)
  34. #生成一个证书请求,一会签发证书时需要的,标箭头的按提示填写,没有箭头标注的为空:
  35. [root@harbor ssl]# openssl req -new -key harbor.key -out harbor.csr
  36. You are about to be asked to enter information that will be incorporated
  37. into your certificate request.
  38. What you are about to enter is what is called a Distinguished Name or a DN.
  39. There are quite a few fields but you can leave some blank
  40. For some fields there will be a default value,
  41. If you enter '.', the field will be left blank.
  42. -----
  43. Country Name (2 letter code) [XX]:CH
  44. State or Province Name (full name) []:BJ
  45. Locality Name (eg, city) [Default City]:BJ
  46. Organization Name (eg, company) [Default Company Ltd]:
  47. Organizational Unit Name (eg, section) []:
  48. Common Name (eg, your name or your server's hostname) []:harbor  #主机名
  49. Email Address []:
  50. Please enter the following 'extra' attributes
  51. to be sent with your certificate request
  52. A challenge password []:
  53. An optional company name []:
  54. #签发证书
  55. [root@harbor ssl]# openssl x509 -req -in harbor.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out harbor.pem -days 3650
  56. #显示如下说明证书发布完成
  57. Signature ok
  58. subject=/C=CH/ST=BJ/L=BJ/O=Default Company Ltd/CN=harbor
  59. Getting CA Private Key
复制代码
注:安装harbor必要docker,记得安装docker

  • 安装harbor
  1. #创建harbor安装目录
  2. [root@harbor ~]# mkdir /data/install -p
  3. [root@harbor ~]# cd /data/install/
  4. #上传harbor离线包到该目录:harbor-offline-installer-v2.3.0-rc3.tgz
  5. #下载harbor离线包的地址:https://github.com/goharbor/harbor/releases/tag/
  6. [root@harbor install]# ll
  7. total 614492
  8. -rw-r--r-- 1 root root 629238614 Apr 11 21:40 harbor-offline-installer-v2.3.0-rc3.tgz
  9. #解压该安装包
  10. [root@harbor install]# tar -xf harbor-offline-installer-v2.3.0-rc3.tgz
  11. [root@harbor install]# ll
  12. total 614492
  13. drwxr-xr-x 2 root root       122 Apr 11 21:42 harbor
  14. -rw-r--r-- 1 root root 629238614 Apr 11 21:40 harbor-offline-installer-v2.3.0-rc3.tgz
  15. [root@harbor install]# cd harbor
  16. [root@harbor harbor]# ll
  17. total 617800
  18. -rw-r--r-- 1 root root      3361 Jun 17  2021 common.sh
  19. -rw-r--r-- 1 root root 632593607 Jun 17  2021 harbor.v2.3.0.tar.gz
  20. -rw-r--r-- 1 root root      7840 Jun 17  2021 harbor.yml.tmpl
  21. -rwxr-xr-x 1 root root      2500 Jun 17  2021 install.sh
  22. -rw-r--r-- 1 root root     11347 Jun 17  2021 LICENSE
  23. -rwxr-xr-x 1 root root      1881 Jun 17  2021 prepare
  24. [root@harbor harbor]# cp harbor.yml.tmpl harbor.yml
  25. #修改配置
  26. [root@harbor harbor]# vim harbor.yml
复制代码
只修改三种地方 一个是主机名 一个是key和pem得位置


  • 安装docker-compose
   上传docker-compose-Linux-x86_64文件到harbor机器
  1. [root@harbor harbor]# ll
  2. total 629776
  3. -rw-r--r-- 1 root root      3361 Jun 17  2021 common.sh
  4. -rw-r--r-- 1 root root  12254160 Apr 11 22:44 docker-compose-Linux-x86_64.64
  5. -rw-r--r-- 1 root root 632593607 Jun 17  2021 harbor.v2.3.0.tar.gz
  6. -rw-r--r-- 1 root root      7826 Apr 11 22:41 harbor.yml
  7. -rw-r--r-- 1 root root      7840 Jun 17  2021 harbor.yml.tmpl
  8. -rwxr-xr-x 1 root root      2500 Jun 17  2021 install.sh
  9. -rw-r--r-- 1 root root     11347 Jun 17  2021 LICENSE
  10. -rwxr-xr-x 1 root root      1881 Jun 17  2021 prepare
  11. You have new mail in /var/spool/mail/root
  12. [root@harbor harbor]# mv docker-compose-Linux-x86_64.64 /usr/bin/docker-compose
  13. [root@harbor harbor]# chmod +x /usr/bin/docker-compose
  14. [root@harbor harbor]# /bin/bash
  15. [root@harbor harbor]# docker-compose version
  16. docker-compose version 1.26.2, build eefe0d31
  17. docker-py version: 4.2.2
  18. CPython version: 3.7.7
  19. OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019
  20. [root@harbor harbor]#
复制代码

  • 上传harbor所必要得镜像
   docker-harbor-2-3-0.tar.gz
  1. #解压镜像
  2. [root@harbor harbor]# docker load -i docker-harbor-2-3-0.tar.gz
  3. [root@harbor harbor]# docker images
  4. REPOSITORY                      TAG       IMAGE ID       CREATED       SIZE
  5. goharbor/harbor-exporter        v2.3.0    fa4ecf260b3a   2 years ago   80.7MB
  6. goharbor/chartmuseum-photon     v2.3.0    199be7eb1b5b   2 years ago   178MB
  7. goharbor/redis-photon           v2.3.0    3cc2c3e315a2   2 years ago   191MB
  8. goharbor/trivy-adapter-photon   v2.3.0    3c3dc5fc0529   2 years ago   164MB
  9. goharbor/notary-server-photon   v2.3.0    a8e3a26ef25a   2 years ago   105MB
  10. goharbor/notary-signer-photon   v2.3.0    e8776cc92436   2 years ago   102MB
  11. goharbor/harbor-registryctl     v2.3.0    4cf0d9bc3086   2 years ago   132MB
  12. goharbor/registry-photon        v2.3.0    222f05a9ab07   2 years ago   81MB
  13. goharbor/nginx-photon           v2.3.0    78f6ae7adc04   2 years ago   44MB
  14. goharbor/harbor-log             v2.3.0    9446a5b39706   2 years ago   194MB
  15. goharbor/harbor-jobservice      v2.3.0    bac328ac1a47   2 years ago   170MB
  16. goharbor/harbor-core            v2.3.0    7bbebce7798c   2 years ago   157MB
  17. goharbor/harbor-portal          v2.3.0    c4f22964cbf3   2 years ago   57.3MB
  18. goharbor/harbor-db              v2.3.0    fc74663d9e30   2 years ago   262MB
  19. goharbor/prepare                v2.3.0    a830321ca695   2 years ago   291MB
  20. #安装harbor
  21. [root@harbor harbor]# cd /data/install/harbor
  22. [root@harbor harbor]# ./install.sh
复制代码
看到以下内容 成名乐成

5. 安装乐成
   默认用户名:admin
默认暗码:Harbor12345
  


6. 新建项目



  • 其他docker机器配置该镜像仓库
  1. #两台服务器配置本地hosts
  2. vim /etc/hosts
  3. 192.168.40.180 test-server01
  4. 192.168.40.181 harbor
  5. #修改180机器得daemon.json配置
  6. [root@test-server01 ~]# vim /etc/docker/daemon.json
  7. {
  8.   "registry-mirrors":["https://vl2nkrv0.mirror.aliyuncs.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn","https://dockerhub.azk8s.cn","http://hub-mirror.c.163.com"],
  9.   "insecure-registries": ["192.168.40.181","harbor"]
  10. }
  11. #harbor机器得IP和主机名
  12. #重启docker
  13. [root@test-server01 ~]# systemctl restart docker
复制代码

  • docker登录harbor进行测试
  1. [root@test-server01 ~]# docker login 192.168.40.181
  2. Username: admin
  3. Password:
  4. WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
  5. Configure a credential helper to remove this warning. See
  6. https://docs.docker.com/engine/reference/commandline/login/#credentials-store
  7. Login Succeeded
  8. #打包一个镜像上传到test项目
  9. [root@test-server01 ~]# docker images
  10. REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
  11. tomcat        v1        422fe599256a   4 weeks ago   803MB
  12. nginx         v1        f436f09d9c6c   4 weeks ago   342MB
  13. inter-image   latest    5eb7b6cd9fb7   4 weeks ago   342MB
  14. volume        latest    4fd3ed843dab   2 years ago   231MB
  15. centos        latest    5d0da3dc9764   2 years ago   231MB
  16. [root@test-server01 ~]#
  17. #以本机有的镜像tomcat为例进行打标签
  18. [root@test-server01 ~]# docker tag tomcat:v1  192.168.40.181/test/tomcat:v1
  19. [root@test-server01 ~]# docker images
  20. REPOSITORY                   TAG       IMAGE ID       CREATED       SIZE
  21. 192.168.40.181/test/tomcat   v1        422fe599256a   4 weeks ago   803MB
  22. tomcat                       v1        422fe599256a   4 weeks ago   803MB
  23. nginx                        v1        f436f09d9c6c   4 weeks ago   342MB
  24. inter-image                  latest    5eb7b6cd9fb7   4 weeks ago   342MB
  25. centos                       latest    5d0da3dc9764   2 years ago   231MB
  26. volume                       latest    4fd3ed843dab   2 years ago   231MB
  27. #上传打上标签得镜像
  28. [root@test-server01 ~]#  docker push 192.168.40.181/test/tomcat:v1
  29. The push refers to repository [192.168.40.181/test/tomcat]
  30. baa34f4b2d36: Pushed
  31. 9098e168cf25: Pushed
  32. 8e1cd85f5863: Pushed
  33. 70e115906be4: Pushed
  34. 6900d18cbe12: Pushed
  35. 49461804abc1: Pushed
  36. 2e412669ee56: Pushed
  37. 74ddd0ec08fa: Pushed
  38. v1: digest: sha256:99c83711e386c7de760bc2c549b231995928bcb37b0d27b7d6478b6c332a5200 size: 1999
  39. #成功上传到镜像仓库
复制代码

  • harbor web页面检察
已经有这个tomcat包


  • 测试从harbor下载镜像
  1. #删除本地镜像
  2. [root@test-server01 ~]# docker images |grep test/tomcat
  3. 192.168.40.181/test/tomcat   v1        422fe599256a   4 weeks ago   803MB
  4. [root@test-server01 ~]# docker rmi 192.168.40.181/test/tomcat:v1
  5. Untagged: 192.168.40.181/test/tomcat:v1
  6. Untagged: 192.168.40.181/test/tomcat@sha256:99c83711e386c7de760bc2c549b231995928bcb37b0d27b7d6478b6c332a5200
  7. [root@test-server01 ~]# docker images |grep test/tomcat
  8. #下载镜像
  9. [root@test-server01 ~]# docker pull 192.168.40.181/test/tomcat:v1
  10. v1: Pulling from test/tomcat
  11. Digest: sha256:99c83711e386c7de760bc2c549b231995928bcb37b0d27b7d6478b6c332a5200
  12. Status: Downloaded newer image for 192.168.40.181/test/tomcat:v1
  13. 192.168.40.181/test/tomcat:v1
  14. You have new mail in /var/spool/mail/root
  15. [root@test-server01 ~]# docker images |grep test/tomcat
  16. 192.168.40.181/test/tomcat   v1        422fe599256a   4 weeks ago   803MB
复制代码
页面可以看到下载次数已经是1了


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

鼠扑

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表