5 Commits
Author SHA1 Message Date
yeasy 12c2acca52 fix(命令): 五处照抄跑不起来,另修四处违反本书自己规则的写法
跑不起来的五处:

- 11.5:604 的 Compose 示例里 `db:` 顶在第 0 列,是**顶级键而不是服务**。
  实测 yaml 解析结果是 `{'services': None, 'db': {...}}`,`docker compose up`
  直接报错。同文件其他服务示例都缩进正确。
- 10.3 的 `docker manifest create` 把 `--amend` 当成每个 manifest 的前缀写了
  两遍。upstream `docker/cli` 里它是 `BoolVarP(&opts.amend, "amend", "a", ...)`,
  不取值;用法是 `create MANIFEST_LIST MANIFEST [MANIFEST...]`。照抄不仅参数
  错位,还会打开"修改已有列表"的语义。改为直接跟位置参数。
- 21.7:288 `apk add postgresql-contrib pg-stat-monitor`。核对 Alpine v3.23 的
  APKINDEX(427828 行,直接解包官方索引):这两个包名都**不存在**,Alpine 只
  提供带主版本号的 `postgresql16-contrib` 等;`apk add` 遇到未知包会中止,
  该 Dockerfile 卡在第二步。改为 postgresql16-contrib 并去掉 pg-stat-monitor,
  同时注明原因。
- 19.3:528 用 `pip install --user` 装到 `/root/.local`,运行阶段却 `USER nobody`。
  Debian 的 `/root` 是 0700,nobody 无法进入,容器起来就找不到依赖。改为装到
  `/opt/pydeps`(PYTHONUSERBASE)并同步 COPY 与 PATH。
- 11.8:202 的 `WORDPRESS_REDIS_HOST` 不被官方镜像识别——`wp-config-docker.php`
  只映射固定的一组 WORDPRESS_* 变量,其中没有 Redis 项;Redis Object Cache
  插件读的是 PHP 常量 `WP_REDIS_HOST`。改为经 `WORDPRESS_CONFIG_EXTRA` 注入。

违反本书自己规则的四处:

- 全书 21 处 `FROM ... as`(13 处在正文、8 处在 Dockerfile)用小写 as,会被
  `docker buildx build --check` 的 FromAsCasing 报
  `'as' and 'FROM' keywords' casing do not match`——而本书正是拿 `--check`
  当准绳(7.6:16、10.2:23),且自己另有 12 处已经写成大写 AS。统一为 AS,
  并把 7.17:174 那句"可以使用 `as` 来为某一阶段命名"一并改掉并附上检查项链接。
- 6.3:137 建议"可替换为 `httpd:latest`",而同文件 22 行之后就写着"不要使用
  `latest`,以保证部署的可重复性"。删去该建议。
- 7.6:253 写"多个 ENV 会创建多层",而 4.5:5 明确区分过:只改元数据的指令
  不新增文件系统层。ENV 正属于后者。改为"多出几条构建历史记录"。

核验方式的一点说明:查 Alpine 包是否存在时,我先用网页搜索接口做了一遍,
结果四个包名全部"命中"(包括本不该存在的那个)——那个页面会把查询词回显。
改用官方 APKINDEX 解包比对后才得到可信结论,两种方法交叉确认后才动手。
2026-09-04 15:01:00 -07:00
yeasy 9fdffa9d91 fix(content): harden Docker practice guide 2026-06-16 21:23:21 -07:00
yeasy 0cfd55af7b fix(content): repair Django tutorial crash and complete the hardening sweep
Follow-ups to the 9 secret-hardening commits (each verified against
docs.docker.com / vendor docs; one outright new bug found and fixed):

- 11.6: eb5e4397 changed settings.py to a hard os.environ lookup but the
  web service never receives POSTGRES_PASSWORD (only db does; DATABASE_URL
  is set but never read) -> step-6 'docker compose up' crashed with
  KeyError. Pass the var to web; harden the leftover literal password in
  the 配置详解 snippet that contradicted the new guidance two lines down;
  blank line after the inserted sentence (bold heading merged into the
  paragraph); dev/prod table no longer claims dev uses 明文 passwords
- 11.8: FAQ still told readers to check passwords in .env after the same
  file banned passwords in .env -> point at secrets/db_password.txt;
  backup sidecar env vars updated to tiredofit/db-backup 4.x interface
  (DB01_* + DB01_PASS_FILE + DB01_BACKUP_INTERVAL - the unprefixed DB_*
  names are ignored by current :latest; verified against upstream README)
- demo/wordpress: compose now references secrets files that ship nowhere
  -> add README with the creation commands from 11.8; demo/django: align
  with the hardened 11.6 (env-injected password, passed to web too)
- 04_image multistage demos: go build without go.mod fails on module-mode
  Go (reproduced by reviewer on go1.26) -> add 'go mod init helloworld'
  matching the 7.17 doc pattern in all three Dockerfiles
- 21.7: init script reworked init-db.sql -> init-db.sh per the official
  image's env-reading .sh hook - removes the baked 'secure_password' AND
  the CREATE DATABASE myappdb collision with POSTGRES_DB that aborted
  first-boot init (ON_ERROR_STOP); compose passes APP_DB_PASSWORD;
  microservices init.sql mount annotated schema-only (POSTGRES_USER:
  appuser would collide with CREATE USER); Dockerfile-redis healthcheck
  now authenticates via REDISCLI_AUTH read from redis.conf (plain
  redis-cli ping gets NOAUTH against requirepass - same class as the
  compose sibling eb5e4397 already fixed); dev-container dev/dev creds
  annotated local-only
- 19.3: Grafana admin password 'admin' sat directly under the newly added
  security warning -> env-injected like the rest of the stack
2026-06-10 12:06:57 -07:00
yeasy 1cdd3c582a fix(content): harden Docker examples 2026-06-01 10:33:50 -07:00
Baohua Yang 2264a7ae72 Release v1.5.0: Restructure chapters and update for Docker v30.x 2026-02-04 22:14:22 -08:00