Files
docker_practice/06_repository/6.2_registry.md
T
yeasy b81816bb07 fix(content): 修正已随上游变化失效的版本事实与镜像引用
深审发现 14 处正文与上游现状不符(另有 4 处在 .agent/ 本地记忆,不入库)。
全部经官方一手源核验,并由独立复核者逐条尝试证伪后保留。

**Docker Content Trust 已从 CLI 移除(本书基线正是 Engine 29.x)**
- 18.6:`docker trust`、`DOCKER_CONTENT_TRUST` 的示例此前标为“历史用法”,
  但未说明命令在 29.x 上根本不存在。Engine 29.0 release notes 原文:
  "Docker Content Trust was removed from the Docker CLI";实测 docker/cli
  的 cli/trust 包在 v28.5.0 返回 200、v29.0.0 返回 404
- 2.3、18.6:DCT 不再是“弃用阶段、时间线待公布”——官方 retired 页已给出
  完整时间表(notary.docker.io 2026-12-08 关闭)
- 注意:`--disable-content-trust` 是 MarkDeprecated(隐藏但仍接受为 no-op),
  不是“不可用”。初版提议写成不可用,经复核纠正后才落地

**etcd 维护分支写反了**
- 15_etcd README/15.1/15.2 均称“3.5 已退出维护窗口”,但 2026-07-23 官方与
  v3.7.1、v3.6.14 同批发布了 v3.5.33,公告称三个分支均在维护;3.4 EOL 也应
  是 2026-06(v3.4.45),非 5 月

**其他上游变化**
- 17.6:containerd 首个 2.x LTS 是 2.0(2024-11-05 起),非 2.3
- 6.4:`sonatype/nexus3:3.69` 这个 tag 从不存在(Sonatype 用三段式),改 3.69.0
- appendix/repo/centos:`rockylinux` 官方镜像已冻结(最后推送 2024-05-30),
  改用官方指引的 `rockylinux/rockylinux`(2026-07-12 仍在更新)
- 6.2/6.3:docs.docker.com/registry/ 已 301 到 retired 页,改指
  distribution.github.io(实测 200)
- 6.1:`docker search centos` 的示例输出补上上游现有的 DEPRECATED 标记

**刻意未改**:`minio/minio` 虽在 Docker Hub 标记 archived,但提议替换的
quay.io/minio/minio 最新 tag 停在 2024-07-31,比 Docker Hub 的 2025-09-07
更旧,照改会把读者引向更陈旧的仓库,留待作者定夺。

验证:check_project_rules 202 文件全过、emphasis 全过、40 测试通过、format 干净。
2026-07-28 20:12:47 -07:00

121 lines
5.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 6.2 私有仓库
有时候使用 Docker Hub 这样的公共仓库可能不方便用户可以创建一个本地仓库供私人使用
本节介绍如何使用本地仓库
[Docker Registry](https://distribution.github.io/distribution/) 是官方提供的工具,可以用于构建私有的镜像仓库。本文示例沿用 [distribution/distribution](https://github.com/distribution/distribution) v2.x 兼容路径;新生产部署应评估 Distribution 3.x,并核对配置路径、迁移说明和生态兼容性。
### 6.2.1 安装运行 docker-registry
#### 容器运行
如果您需要搭建私有仓库可以通过官方提供的 `registry` 镜像快速部署
你可以使用官方 `registry` 镜像来运行
```bash
$ docker run -d -p 5000:5000 --restart=always --name registry registry:2
```
> **版本说明**使用 `registry:2` 表示 Docker Registry 2.x 兼容示例Distribution 3.x 已发布稳定版本不要直接把本章 v2 配置原样套到 v3 生产环境升级前应阅读迁移说明并做兼容测试旧版本 Registry 1.x 已停止维护不建议使用
这将使用官方的 `registry` 镜像来启动私有仓库默认情况下仓库会被创建在容器的 `/var/lib/registry` 目录下你可以通过 `-v` 参数来将镜像文件存放在本地的指定路径例如下面的例子将上传的镜像放到本地的 `/opt/data/registry` 目录
```bash
$ docker run -d \
-p 5000:5000 \
-v /opt/data/registry:/var/lib/registry \
registry:2
```
### 6.2.2 在私有仓库上传搜索下载镜像
创建好私有仓库之后就可以使用 `docker tag` 来标记一个镜像然后推送它到仓库例如私有仓库地址为 `127.0.0.1:5000`
先在本机查看已有的镜像
```bash
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest ba5877dc9bec 6 weeks ago 192.7 MB
```
使用 `docker tag` `ubuntu:latest` 这个镜像标记为 `127.0.0.1:5000/ubuntu:latest`
格式为 `docker tag IMAGE[:TAG] [REGISTRY_HOST[:REGISTRY_PORT]/]REPOSITORY[:TAG]`
```bash
$ docker tag ubuntu:latest 127.0.0.1:5000/ubuntu:latest
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest ba5877dc9bec 6 weeks ago 192.7 MB
127.0.0.1:5000/ubuntu latest ba5877dc9bec 6 weeks ago 192.7 MB
```
使用 `docker push` 上传标记的镜像
```bash
$ docker push 127.0.0.1:5000/ubuntu:latest
The push refers to repository [127.0.0.1:5000/ubuntu]
373a30c24545: Pushed
a9148f5200b0: Pushed
cdd3de0940ab: Pushed
fc56279bbb33: Pushed
b38367233d37: Pushed
2aebd096e0e2: Pushed
latest: digest: sha256:fe4277621f10b5026266932ddf760f5a756d2facd505a94d2da12f4f52f71f5a size: 1568
```
`curl` 查看仓库中的镜像
```bash
$ curl 127.0.0.1:5000/v2/_catalog
{"repositories":["ubuntu"]}
```
这里可以看到 `{"repositories":["ubuntu"]}`表明镜像已经被成功上传了
先删除已有镜像再尝试从私有仓库中下载这个镜像
```bash
$ docker image rm 127.0.0.1:5000/ubuntu:latest
$ docker pull 127.0.0.1:5000/ubuntu:latest
Pulling repository 127.0.0.1:5000/ubuntu:latest
ba5877dc9bec: Download complete
511136ea3c5a: Download complete
9bad880da3d2: Download complete
25f11f5fb0cb: Download complete
ebc34468f71d: Download complete
2318d26665ef: Download complete
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
127.0.0.1:5000/ubuntu latest ba5877dc9bec 6 weeks ago 192.7 MB
```
### 6.2.3 配置非 https 仓库地址
如果你不想使用 `127.0.0.1:5000` 作为仓库地址比如想让本网段的其他主机也能把镜像推送到私有仓库你就得把例如 `192.168.199.100:5000` 这样的内网地址作为私有仓库地址这时你会发现无法成功推送镜像
这是因为 Docker 默认不允许非 `HTTPS` 方式推送镜像我们可以通过 Docker 的配置选项来取消这个限制或者查看下一节配置能够通过 `HTTPS` 访问的私有仓库
#### Linux
默认情况下Docker 强制使用 HTTPS 协议推送镜像如果您搭建的私有仓库是 HTTP 协议需要进行如下配置
对于使用 `systemd` 的系统请在 `/etc/docker/daemon.json` 中写入如下内容 (如果文件不存在请新建该文件)
```json
{
"registry-mirrors": [
"https://docker.your-mirror.example.com"
],
"insecure-registries": [
"192.168.199.100:5000"
]
}
```
> 注意该文件必须符合 `json` 规范否则 Docker 将不能启动镜像加速器地址请替换为实际可用的源具体配置参见 [3.9 镜像加速器](../03_install/3.9_mirror.md)
### 6.2.4 其他
对于 Docker Desktop for WindowsDocker Desktop for Mac 在设置中的 `Docker Engine` 中进行编辑增加和上边一样的字符串即可