From ea26f9629770cd10c442225e9e37103e0b8c064a Mon Sep 17 00:00:00 2001 From: yeasy Date: Mon, 25 May 2026 01:13:10 -0700 Subject: [PATCH] fix(content): remove demo registry credential --- .gitignore | 1 + 06_repository/6.3_registry_auth.md | 9 +++++++-- 06_repository/demo/auth/README.md | 5 +++++ 06_repository/demo/auth/nginx.htpasswd | 2 -- 4 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 06_repository/demo/auth/README.md delete mode 100644 06_repository/demo/auth/nginx.htpasswd diff --git a/.gitignore b/.gitignore index f16d094..1a24a15 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ node_modules/ package-lock.json docker-compose.override.yml +06_repository/demo/auth/nginx.htpasswd # Editor configs .obsidian/ diff --git a/06_repository/6.3_registry_auth.md b/06_repository/6.3_registry_auth.md index 6ef6a75..43eeb77 100644 --- a/06_repository/6.3_registry_auth.md +++ b/06_repository/6.3_registry_auth.md @@ -70,6 +70,8 @@ $ openssl x509 -req -days 750 -in "site.csr" -sha256 \ -CA "root-ca.crt" -CAkey "root-ca.key" -CAcreateserial \ -out "docker.domain.com.crt" -extfile "site.cnf" -extensions server ``` + +配套 demo 中的 [`ssl/README.md`](demo/ssl/README.md) 只保留本地生成证书的占位说明,真实私钥和证书不应提交到仓库。 这样已经拥有了 `docker.domain.com` 的网站 SSL 私钥 `docker.domain.com.key` 和 SSL 证书 `docker.domain.com.crt` 及 CA 根证书 `root-ca.crt`。 新建 `ssl` 文件夹并将 `docker.domain.com.key` `docker.domain.com.crt` `root-ca.crt` 这三个文件移入,删除其他文件。 @@ -101,7 +103,7 @@ auth: realm: basic-realm path: /etc/docker/registry/auth/nginx.htpasswd http: - addr: :443 + addr: :5000 host: https://docker.domain.com headers: X-Content-Type-Options: [nosniff] @@ -130,6 +132,7 @@ $ docker run --rm \ > 将上面的 `username` `password` 替换为你自己的用户名和密码。 > > **安全提示**:上述命令会将密码明文暴露在 shell 历史记录和进程列表中。生产环境建议使用交互式方式输入密码(不带 `-b` 参数),或通过环境变量/文件传入。 +> 配套 demo 的 [`auth/README.md`](demo/auth/README.md) 仅说明本地生成步骤,生成的 `auth/nginx.htpasswd` 已被忽略,不应提交。 > **版本说明**:使用 `httpd:2.4-alpine` 基于 Apache 2.4 的精简镜像。如需其他版本,可替换为 `httpd:latest` 或指定具体版本号如 `httpd:2.4.58-alpine`。 @@ -142,7 +145,7 @@ services: registry: image: registry:2 ports: - - "443:443" + - "443:5000" volumes: - ./:/etc/docker/registry - registry-data:/var/lib/registry @@ -151,6 +154,8 @@ volumes: registry-data: ``` +本书配套的 `06_repository/demo/` 也采用同样约定:容器内 registry 监听 `:5000`,宿主机通过 `443:5000` 暴露 HTTPS 服务。这样可以避免在容器内占用特权端口,同时仍让客户端使用 `https://docker.domain.com` 访问。 + > **版本说明**:Compose 配置中明确指定 `registry:2` 版本。生产环境建议固定版本号(如 `registry:2.8.3`)而非使用 `latest`,以保证部署的可重复性。 ### 6.3.5 修改 Hosts 文件 diff --git a/06_repository/demo/auth/README.md b/06_repository/demo/auth/README.md new file mode 100644 index 0000000..c033077 --- /dev/null +++ b/06_repository/demo/auth/README.md @@ -0,0 +1,5 @@ +# Generated Authentication File + +Run the `htpasswd` command in section 6.3.3 to generate `nginx.htpasswd` locally before starting the demo registry. + +Do not commit generated password hashes. diff --git a/06_repository/demo/auth/nginx.htpasswd b/06_repository/demo/auth/nginx.htpasswd deleted file mode 100644 index 4a9e7f9..0000000 --- a/06_repository/demo/auth/nginx.htpasswd +++ /dev/null @@ -1,2 +0,0 @@ -username:$2y$05$TRWvCC6ilpKpY3ICifw32Ok3.8SpG3etq8O5WGdCm9wvyDhtSbRgy -