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

Docker搭建官方私有仓库registry及相关配置

(企业不推荐使用registry)

Docker 中,当我们执行 docker pull xxx 的时候 ,它实际上是从 https://registry.hub.docker.com/ 这个地址去查找,这就是Docker公司为我们提供的公共仓库。

在工作中,我们不可能把企业项目push到公有仓库进行管理。所以为了更好的管理镜像,Docker不仅提供了一个中央仓库,同时也允许我们搭建本地私有仓库。

docker 官方提供的私有仓库 registry,用起来虽然简单 ,但在管理的功能上存在不足。 Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,harbor使用的是官方的docker registry(v2命名是distribution)服务去完成。harbor在docker distribution的基础上增加了一些安全、访问控制、管理的功能以满足企业对于镜像仓库的需求。
下载地址:https://github.com/goharbor/harbor/releases

此文介绍registry私有仓库搭建方法。


1、私有仓库搭建与配置

(0)搜索registry镜像(可跳过)

[root@localhost java]# docker search registry

  
  

在这里插入图片描述


(1)拉取最新版(latest)私有仓库镜像:registry

[root@localhost java]# docker pull registry

  
  

在这里插入图片描述
查看镜像:
在这里插入图片描述


(2)创建并启动私有仓库容器(默认已启动)

[root@localhost java]# docker run -di --name=registry -p 5000:5000 registry:latest

  
  

查看已启动的容器:
在这里插入图片描述


(3)暂时关闭防火墙(根据实际情况可跳过

[root@localhost ~]# systemctl stop firewalld

  
  

重启防火墙命令:service iptables restart


(4)打开浏览器,输入地址:http://192.168.116.161:5000/v2/_catalog 看到{"repositories":[]} 表示私有仓库搭建成功并且内容为空。

注:192.168.116.161 为linux服务器宿主系统IP。

在这里插入图片描述


(5)修改daemon.json(让docker信任私有仓库地址

[root@localhost java]# vi /etc/docker/daemon.json

  
  

添加以下内容,保存退出。

{"insecure-registries":["192.168.116.161:5000"]} 

  
  

内容如下图:
在这里插入图片描述


(6)重启docker 服务

[root@localhost java]# systemctl daemon-reload
[root@localhost java]# systemctl restart docker

  
  

2、镜像上传至私有仓库

(1)标记镜像为私有仓库的镜像

使用 docker tag 命令标记本地镜像 jdk1.8,将其归入某一仓库。

格式:

docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]

【示例】:

原有镜像:

在这里插入图片描述

如,将镜像 jdk1.8:latest 标记为 192.168.116.161:5000/jdk1.8 镜像:

[root@localhost java]# docker tag jdk1.8:latest 192.168.116.161:5000/jdk1.8

  
  

在这里插入图片描述


(2)启动私服容器(registry)

[root@localhost java]# docker start registry

  
  

(3)上传标记的镜像

[root@localhost java]# docker push 192.168.116.161:5000/jdk1.8

  
  

在这里插入图片描述


(4)访问私服仓库

注:192.168.116.161 为linux服务器宿主系统IP。

第1种:命令行输出

[root@localhost java]# curl http://192.168.116.161:5000/v2/_catalog
{"repositories":["jdk1.8"]}
[root@localhost java]# 

  
  

第2种:浏览器输出

浏览器访问私服:http://192.168.116.161:5000/v2/_catalog

如下图,可以看到jdk1.8已经上传到了私有仓库中:

在这里插入图片描述


2、附:删除私有仓库镜像方法

(1)获取私有仓库镜像sha256值

格式:

curl --header “Accept:application/vnd.docker.distribution.manifest.v2+json” -I -X GET http://镜像IP地址/v2/镜像名称/manifests/镜像版本

如,获取springboot_demo的sha256值的命令:

curl --header “Accept:application/vnd.docker.distribution.manifest.v2+json” -I -X GET http://192.168.116.161:5000/v2/springboot_demo/manifests/0.0.1-SNAPSHOT

操作详情:

[root@localhost java]# curl --header "Accept:application/vnd.docker.distribution.manifest.v2+json" -I -X GET http://192.168.116.161:5000/v2/springboot_demo/manifests/0.0.1-SNAPSHOT
HTTP/1.1 200 OK
Content-Length: 949
Content-Type: application/vnd.docker.distribution.manifest.v2+json
Docker-Content-Digest: sha256:8b4595870df7c01953970ea497da6a8291f90a7cef08cc42580aa4b4f914dee1
Docker-Distribution-Api-Version: registry/2.0
Etag: "sha256:8b4595870df7c01953970ea497da6a8291f90a7cef08cc42580aa4b4f914dee1"
X-Content-Type-Options: nosniff
Date: Mon, 30 Nov 2020 19:01:34 GMT
[root@localhost java]#

  
  

(2)删除私有仓库镜像

格式:

curl -I -X DELETE http://镜像IP地址:5000/v2/镜像名称/manifests/镜像对应sha256值

如,删除私有仓库springboot_demo镜像的命令:

curl -I -X DELETE http://192.168.116.161:5000/v2/springboot_demo/manifests/8b4595870df7c01953970ea497da6a8291f90a7cef08cc42580aa4b4f914dee1

操作详情:

[root@localhost java]# curl -I -X DELETE http://192.168.116.161:5000/v2/springboot_demo/manifests/8b4595870df7c01953970ea497da6a8291f90a7cef08cc42580aa4b4f914dee1
HTTP/1.1 405 Method Not Allowed
Content-Type: application/json; charset=utf-8
Docker-Distribution-Api-Version: registry/2.0
X-Content-Type-Options: nosniff
Date: Mon, 30 Nov 2020 19:06:38 GMT
Content-Length: 78
[root@localhost java]#

  
  

如上,提示405没有权限。权限问题,暂时不知道如何解决。


http://www.kler.cn/a/372263.html

相关文章:

  • 基于树莓派的安保巡逻机器人--(一、快速人脸录入与精准人脸识别)
  • DGUS屏使用方法
  • 易至狂欢购车季火热开启,EV3青春版打造年轻一代出行新选择
  • 【MMIN】缺失模态想象网络用于不确定缺失模态的情绪识别
  • 相关矩阵图——Python实现
  • 【Android】Kotlin教程(4)
  • Ubuntu20.04安装VM tools并实现主机和虚拟机之间文件夹共享
  • 基于微信小程序的小区管理系统设计与实现(lw+演示+源码+运行)
  • uniapp跨域问题,在开发环境中配置
  • Unity(四十八):Unity与Web双向交互
  • Spring Cloud 微服务全面概述
  • 【系统面试篇】简述进程调度算法
  • CTF-PWN: 虚表(vtable)
  • Vue学习记录之二十二 Vue3+vite+electron 构建项目实例
  • 别被忽悠了 Lua 数组真的也可以从 0 开始索引?
  • 10 最长回文子串、买卖股票的最好时机(一)、[NOIP2002 普及组] 过河卒24_10_30
  • CodeQL学习笔记(3)-QL语法(模块、变量、表达式、公式和注解)
  • @tarojs/components 和 taro-ui 中的组件之间的区别
  • HarmonyOS NEXT API12最新版 端云一体化开发-创建端云一体化项目流程
  • docker部署SQL审核平台Archery