mirror of
https://github.com/yeasy/docker_practice.git
synced 2026-08-11 08:57:34 +00:00
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:eb5e4397changed 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 siblingeb5e4397already 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
This commit is contained in:
@@ -167,13 +167,13 @@ $ docker compose exec -T db sh -c 'tmp=$(mktemp) && printf "[client]\nuser=wordp
|
||||
volumes:
|
||||
- ./backups:/backup
|
||||
environment:
|
||||
- DB_TYPE=mysql
|
||||
- DB_HOST=db
|
||||
- DB_NAME=wordpress
|
||||
- DB_USER=wordpress
|
||||
# 选用支持从文件读取密码的备份镜像,或用自定义 entrypoint 从 secret 文件注入。
|
||||
- DB_PASS_FILE=/run/secrets/db_password
|
||||
- DB_DUMP_FREQ=1440 # 每天备份一次
|
||||
# tiredofit/db-backup 4.x 起按 DB01_ 前缀配置备份任务,并原生支持 _FILE 读密
|
||||
- DB01_TYPE=mysql
|
||||
- DB01_HOST=db
|
||||
- DB01_NAME=wordpress
|
||||
- DB01_USER=wordpress
|
||||
- DB01_PASS_FILE=/run/secrets/db_password
|
||||
- DB01_BACKUP_INTERVAL=1440 # 每天备份一次(单位:分钟)
|
||||
secrets:
|
||||
- db_password
|
||||
depends_on:
|
||||
@@ -212,7 +212,7 @@ WordPress 支持 Redis 缓存以提高性能。
|
||||
**现象**:访问页面显示 “Error establishing a database connection”。**排查**:
|
||||
|
||||
1. 检查 `docker compose logs wordpress`
|
||||
2. 确认 `.env` 中的密码与 YAML 文件引用一致
|
||||
2. 确认 `secrets/db_password.txt` 的内容正确,且与数据库初始化时使用的密码一致(改密码后需要重建 db 数据卷)
|
||||
3. 确认 `WORDPRESS_DB_HOST` 也是 `db` (服务名)
|
||||
4. MySQL 8.4 可能需要几秒钟启动,WordPress 会自动重试,稍等片刻即可。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user