docker仓库

server/2024/9/25 11:08:10/

一、创建 Docker 镜像仓库

  1. 启动私有仓库容器
    通过 Docker 启动一个私有镜像仓库。这里使用官方的 registry 镜像。
#docker run -d:在后台运行一个容器
#-p 5000:5000:将容器内的 5000 端口映射到宿主机的 5000 端口,私有仓库将通过此端口访问。
#--restart=always:保证容器在主机重启后自动启动。
#--name registry:为该容器命名为 registry。
#-v /opt/myregistry:/var/lib/registry:将主机目录 /opt/myregistry 挂载到容器的 /var/lib/registry,用于持久化存储仓库数据。
[root@localhost lib]# docker run -d -p 5000:5000 --restart=always --name registry -v /opt/myregistry:/var/lib/registry registryUnable to find image 'registry:latest' locally
latest: Pulling from library/registry
1cc3d825d8b2: Pull complete 
85ab09421e5a: Pull complete 
40960af72c1c: Pull complete 
e7bb1dbb377e: Pull complete 
a538cc9b1ae3: Pull complete 
Digest: sha256:ac0192b549007e22998eb74e8d8488dcfe70f1489520c3b144a6047ac5efbe90
Status: Downloaded newer image for registry:latest
e88bcb2919efad55b76fc7c00f1fad60954b83f18e01c35da565dd20a4b9815c
[root@localhost lib]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
nginx        latest    39286ab8a5e1   5 weeks ago     188MB
registry     latest    75ef5b734af4   11 months ago   25.4MB
  1. 修改 Docker 配置文件支持 HTTP 访问
    默认情况下,Docker 只允许使用 HTTPS 安全地与仓库进行通信。为了允许使用 HTTP 访问你的私有仓库,需要修改 Docker 的配置文件。
vi /etc/docker/daemon.json
#加入
"insecure-registries": ["192.168.29.210:5000"]

在这里插入图片描述
3. 重启 Docker 服务
修改配置后需要重启 Docker 服务,以便让修改生效。

[root@localhost lib]# systemctl restart docker

二、操作镜像

  1. 修改镜像标签
    以nginx镜像举例,现在你需要为这个镜像打上标签,并推送到私有仓库。以下是将 nginx:latest 镜像重命名为适合上传私有仓库的标签。
# docker tag:用于给现有的镜像打标签。
# 192.168.29.210:5000/eden/nginx:1.0:新标签格式为 [仓库地址]/[命名空间]/[镜像名]:[版本号]。
[root@localhost ~]# docker tag nginx:latest 192.168.29.210:5000/eden/nginx:1.0
  1. 推送镜像到私有仓库
    打完标签后,将镜像推送到你的私有仓库:
# docker push:将本地镜像上传到指定仓库。
[root@localhost ~]# docker push  192.168.29.210:5000/eden/nginx:1.0
The push refers to repository [192.168.29.210:5000/eden/nginx]
11de3d47036d: Pushed 
16907864a2d0: Pushed 
2bdf51597158: Pushed 
0fc6bb94eec5: Pushed 
eda13eb24d4c: Pushed 
67796e30ff04: Pushed 
8e2ab394fabf: Pushed 
1.0: digest: sha256:596c783ac62b9a43c60edb876fe807376cd5022a4e25e89b9a9ae06c374299d4 size: 1778
  1. 拉取镜像
    从你的私有仓库中拉取该镜像进行测试:
[root@localhost ~]# docker pull 192.168.29.210:5000/eden/nginx:1.0
1.0: Pulling from eden/nginx
Digest: sha256:596c783ac62b9a43c60edb876fe807376cd5022a4e25e89b9a9ae06c374299d4
Status: Image is up to date for 192.168.29.210:5000/eden/nginx:1.0
192.168.29.210:5000/eden/nginx:1.0
[root@localhost ~]# docker images
REPOSITORY                       TAG       IMAGE ID       CREATED         SIZE
nginx                            latest    39286ab8a5e1   5 weeks ago     188MB
192.168.29.210:5000/eden/nginx   1.0       39286ab8a5e1   5 weeks ago     188MB
registry                         latest    75ef5b734af4   11 months ago   25.4MB
  1. 查看私有仓库中的镜像列表
    通过 curl 查看私有仓库中有哪些镜像:
[root@localhost ~]# curl 192.168.29.210:5000/v2/_catalog
{"repositories":["eden/nginx"]}

三、增加 Web UI
为了方便管理仓库中的镜像,我们可以为私有仓库增加一个 Web UI。

  1. 拉取 Web UI 镜像
    首先,拉取一个 Docker Registry Web UI 的镜像。这个镜像允许你通过浏览器查看和管理仓库中的镜像。
[root@localhost ~]# docker pull hyper/docker-registry-web
Using default tag: latest
latest: Pulling from hyper/docker-registry-web
04c996abc244: Pull complete 
d394d3da86fe: Pull complete 
bac77aae22d4: Pull complete 
b48b86b78e97: Pull complete 
09b3dd842bf5: Pull complete 
69f4c5394729: Pull complete 
b012980650e9: Pull complete 
7c7921c6fda1: Pull complete 
e20331c175ea: Pull complete 
40d5e82892a5: Pull complete 
a414fa9c865a: Pull complete 
0304ae3409f3: Pull complete 
13effc1a664f: Pull complete 
e5628d0e6f8c: Pull complete 
0b0e130a3a52: Pull complete 
d0c73ab65cd2: Pull complete 
240c0b145309: Pull complete 
f1fd6f874e5e: Pull complete 
40b5e021928e: Pull complete 
88a8c7267fbc: Pull complete 
f9371a03010e: Pull complete 
Digest: sha256:723ffa29aed2c51417d8bd32ac93a1cd0e7ef857a0099c1e1d7593c09f7910ae
Status: Downloaded newer image for hyper/docker-registry-web:latest
docker.io/hyper/docker-registry-web:latest
[root@localhost ~]# docker images
REPOSITORY                       TAG       IMAGE ID       CREATED         SIZE
192.168.29.210:5000/eden/nginx   1.0       39286ab8a5e1   5 weeks ago     188MB
nginx                            latest    39286ab8a5e1   5 weeks ago     188MB
registry                         latest    75ef5b734af4   11 months ago   25.4MB
hyper/docker-registry-web        latest    0db5683824d8   7 years ago     599MB
  1. 启动 Web UI
    启动 Web UI 并连接到你的私有仓库:
#--link registry:将 Web UI 容器与私有仓库容器连接。
#-e REGISTRY_URL:指定私有仓库的地址。
[root@localhost ~]# docker run -d --restart=always -p 8080:8080 --name registry-web --link registry -e REGISTRY_URL=http://192.168.29.210:5000/v2 -e REGISTRY_NAME=localhost:5000 hyper/docker-registry-web
676d60ff47f3491c7c3c76f5894b2a82ce9a63ae719ee23e9193032c719d77ba
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                       COMMAND                   CREATED          STATUS          PORTS                                       NAMES
676d60ff47f3   hyper/docker-registry-web   "start.sh"                35 seconds ago   Up 32 seconds   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp   registry-web
e88bcb2919ef   registry                    "/entrypoint.sh /etc…"   34 minutes ago   Up 33 minutes   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   registry
  1. 访问 Web UI
    在浏览器中访问 http://192.168.29.210:8080,你将看到私有仓库中的镜像列表。
    在这里插入图片描述
    四、设置带 Basic 认证的仓库
    如果你想要为私有仓库添加认证功能,以下是具体步骤。

  2. 安装 httpd-tools 工具
    首先,安装 httpd-tools 工具来生成认证用户和密码。

[root@localhost ~]# yum install httpd-tools -y
  1. 创建认证文件
    创建认证目录并生成用户名为 admin 、密码为 123456 的认证文件:
[root@localhost ~]# mkdir -p /opt/registry-var/auth/
[root@localhost ~]# htpasswd -Bbn admin 123456 > /opt/registry-var/auth/htpasswd
  1. 启动带认证的私有仓库
    现在,启动带有 Basic 认证功能的私有仓库:
[root@localhost ~]# docker stop registry
registry
#REGISTRY_AUTH=htpasswd:启用 htpasswd 认证。
#REGISTRY_AUTH_HTPASSWD_PATH:认证文件的路径。
#注意 因为前面实验已经有了registry  这里容器取名要为registry2 不要重复 
[root@localhost ~]# docker run -d -p 5000:5000 --restart=always --name registry2 -v /opt/registry-var/auth:/auth -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" registry 
e516541c2d0523faba30cbf65238b8092dab24a1b58b3179f0aa611633d1bad5
  1. 登录并推送镜像
    需要登录私有仓库才能进行镜像操作:
[root@localhost ~]# docker login 192.168.29.210:5000
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-storeLogin Succeeded

登录成功后,可以正常推送镜像

[root@localhost ~]# docker push 192.168.29.210:5000/eden/nginx:1.0
The push refers to repository [192.168.29.210:5000/eden/nginx]
11de3d47036d: Pushed 
16907864a2d0: Pushed 
2bdf51597158: Pushed 
0fc6bb94eec5: Pushed 
eda13eb24d4c: Pushed 
67796e30ff04: Pushed 
8e2ab394fabf: Pushed 
1.0: digest: sha256:596c783ac62b9a43c60edb876fe807376cd5022a4e25e89b9a9ae06c374299d4 size: 1778

四、查看私有 Docker 仓库中的镜像,可以通过多种方式进行操作,包括使用命令行工具和 Web UI。以下是一些具体的步骤和方法:


curl http://192.168.29.210:5000/v2/_catalog#查看特定镜像的标签
curl http://192.168.29.210:5000/v2/eden/nginx/tags/list#使用 Web UI 查看  前提是你已经启动了 docker-registry-web
http://192.168.29.210:8080/#登录并查看
curl -u admin:123456 http://192.168.29.210:5000/v2/_catalog

http://www.ppmy.cn/server/121795.html

相关文章

【系统架构设计师】专题:基于架构的软件开发方法 ABSD(详细知识点及历年真题)

更多内容请见: 备考系统架构设计师-核心总结索引 文章目录 一、ABSD概述二、ABSD开发过程1、架构需求2、架构设计3、架构文档化4、架构复审5、架构实现6、对架构进行改变一、ABSD概述 基于体系结构(架构)的软件设计(Architecture-Based Software Design,ABSD) 方法是体系结构…

springframework Ordered接口学习

Ordered接口介绍 完整路径: org.springframework.core.Ordered Ordered 接口是 Spring 框架中的一个核心接口,用于定义对象的顺序。这个接口通常用于需要排序的组件,例如 Spring 中的 Bean、过滤器(Filters)、拦截器…

Java 之泛型详解

1. 泛型是什么? 泛型是 Java 中一种强大的机制,它允许你编写可以与多种数据类型一起工作的代码,而无需在编译时指定具体的类型。这样可以提高代码的灵活性、可读性和安全性。 2. 为什么要使用泛型? 泛型可以帮助我们编写更安全…

chorme浏览器 您的连接不是私密连接

‌当浏览器显示“您的连接不是私密连接,攻击者可能会试图从 localhost 窃取您的信息(例如:密码、消息或信用卡信息)”的警告时,这通常意味着您正在尝试访问的网站的安全证书存在问题,可能是因为它使用的是自…

C语言之初阶指针

目录 前言1. 什么是指针代码展示 2. 计算机如何编址3. 指针类型指针类型的定义指针类型的意义 4. 野指针4.1. **指针未初始化**4.2. **指针越界访问**4.3. **指针指向的空间被释放** 5. 指针运算6. 指针和数组7. 二级指针8. 指针数组总结 前言 本篇将深入探讨C语言中至关重要的…

【C++】托管类和托管函数

托管类和托管函数 1. 托管类 托管类是指在 .NET 环境中运行的类,它们由公共语言运行时(CLR)管理。托管类具有以下特点: 自动内存管理:托管类的实例由 CLR 的垃圾回收机制管理,自动处理内存的分配和释放。…

pg入门5—pg有哪些系统schema

在 PostgreSQL 中,除了用户创建的 schema 之外,系统还自动创建了一些系统 schema,用于管理数据库的元数据、系统信息以及维护操作。以下是 PostgreSQL 中的常见系统 schema: 1. pg_catalog 用途:pg_catalog 是 Postg…

微服务架构---Ribbon\Feign

Ribbon(负载均衡) Ribbon概述 在 SpringCloud 中, Nacos⼀般配合Ribbon进行使用,Ribbon提供了客户端负载均衡的功能,Ribbon利用从Nacos中读取到的服务信息,在调用服务节点提供的服务时,会合理的进行负载。 Ribbon作…