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

docker仓库

一、创建 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

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • NLP 主流应用方向
  • 关于SpringBoot项目使用maven打包由于Test引起的无法正常打包问题解决
  • 【JAVA开源】基于Vue和SpringBoot的甘肃非物质文化网站
  • C#设计模式之访问者模式
  • QT Creator cmake 自定义项目结构, 编译输出目录指定
  • GUI编程19:贪吃蛇小游戏及GUI总结
  • 网络爬虫Request静态页面数据获取
  • 小明,谈谈你对Vue nextTick的理解
  • LabVIEW提高开发效率技巧----使用事件结构优化用户界面响应
  • [模板]树的最长路径
  • API 架构(RPC和RESTful)
  • 翻译:openmax文档
  • STM32与51单片机的区别:是否应该直接学习STM32?
  • [深度学习]神经网络
  • Linux入门学习:Git
  • Eureka 2.0 开源流产,真的对你影响很大吗?
  • github从入门到放弃(1)
  • JavaScript设计模式与开发实践系列之策略模式
  • Laravel Mix运行时关于es2015报错解决方案
  • Material Design
  • opencv python Meanshift 和 Camshift
  • Python代码面试必读 - Data Structures and Algorithms in Python
  • Python学习之路16-使用API
  • react-native 安卓真机环境搭建
  • 大整数乘法-表格法
  • 基于游标的分页接口实现
  • 时间复杂度与空间复杂度分析
  • 你对linux中grep命令知道多少?
  • Linux权限管理(week1_day5)--技术流ken
  • mysql 慢查询分析工具:pt-query-digest 在mac 上的安装使用 ...
  • 组复制官方翻译九、Group Replication Technical Details
  • ​软考-高级-系统架构设计师教程(清华第2版)【第1章-绪论-思维导图】​
  • # Pytorch 中可以直接调用的Loss Functions总结:
  • #70结构体案例1(导师,学生,成绩)
  • #HarmonyOS:Web组件的使用
  • #pragma预处理命令
  • (175)FPGA门控时钟技术
  • (2024,RWKV-5/6,RNN,矩阵值注意力状态,数据依赖线性插值,LoRA,多语言分词器)Eagle 和 Finch
  • (4)事件处理——(7)简单事件(Simple events)
  • (BAT向)Java岗常问高频面试汇总:MyBatis 微服务 Spring 分布式 MySQL等(1)
  • (html转换)StringEscapeUtils类的转义与反转义方法
  • (leetcode学习)236. 二叉树的最近公共祖先
  • (MIT博士)林达华老师-概率模型与计算机视觉”
  • (webRTC、RecordRTC):navigator.mediaDevices undefined
  • (论文阅读22/100)Learning a Deep Compact Image Representation for Visual Tracking
  • (三)Kafka 监控之 Streams 监控(Streams Monitoring)和其他
  • (十)DDRC架构组成、效率Efficiency及功能实现
  • (算法)硬币问题
  • (转)【Hibernate总结系列】使用举例
  • **Java有哪些悲观锁的实现_乐观锁、悲观锁、Redis分布式锁和Zookeeper分布式锁的实现以及流程原理...
  • .NET core 自定义过滤器 Filter 实现webapi RestFul 统一接口数据返回格式
  • .Net Core和.Net Standard直观理解
  • .net framework4与其client profile版本的区别
  • .net 程序发生了一个不可捕获的异常
  • .NET 使用配置文件