ln-731-docker-generator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseln-731-docker-generator
ln-731-docker-generator
Type: L3 Worker
Category: 7XX Project Bootstrap
Parent: ln-730-devops-setup
Generates production-ready Docker configuration for containerized development.
类型: L3 Worker
分类: 7XX 项目初始化
父级: ln-730-devops-setup
生成可用于生产环境的容器化开发Docker配置。
Purpose & Scope
用途与范围
Creates Docker infrastructure for local development and production:
- Does: Generate Dockerfiles, docker-compose, .dockerignore, nginx config
- Does NOT: Build images, start containers, manage deployments
为本地开发和生产环境创建Docker基础设施:
- 支持: 生成Dockerfile、docker-compose、.dockerignore、nginx配置文件
- 不支持: 构建镜像、启动容器、管理部署
Inputs
输入项
| Input | Source | Description |
|---|---|---|
| Stack Type | ln-730 coordinator | frontend, backend-dotnet, backend-python |
| Versions | Auto-detected | Node.js, .NET, Python versions |
| Project Name | Directory name | Used for container naming |
| Ports | Defaults or detected | Frontend: 3000, Backend: 5000/8000, DB: 5432 |
| 输入项 | 来源 | 描述 |
|---|---|---|
| 技术栈类型 | ln-730 协调器 | 前端、后端.NET、后端Python |
| 版本信息 | 自动检测 | Node.js、.NET、Python版本 |
| 项目名称 | 目录名称 | 用于容器命名 |
| 端口配置 | 默认值或自动检测 | 前端:3000,后端:5000/8000,数据库:5432 |
Outputs
输出项
| File | Purpose | Template |
|---|---|---|
| Frontend build & serve | dockerfile_frontend.template |
| Backend build & run | dockerfile_backend_dotnet.template or dockerfile_backend_python.template |
| Service orchestration | docker_compose.template |
| Build context exclusions | dockerignore.template |
| Frontend proxy config | nginx.template |
| 文件 | 用途 | 模板 |
|---|---|---|
| 前端构建与服务部署 | dockerfile_frontend.template |
| 后端构建与运行 | dockerfile_backend_dotnet.template 或 dockerfile_backend_python.template |
| 服务编排 | docker_compose.template |
| 构建上下文排除规则 | dockerignore.template |
| 前端代理配置 | nginx.template |
Workflow
工作流程
Phase 1: Input Validation
阶段1:输入验证
Validate received configuration from coordinator:
- Check stack type is supported (frontend, backend-dotnet, backend-python)
- Verify versions are valid (Node 18+, .NET 8+, Python 3.10+)
- Confirm project directory exists
Output: Validated configuration or error
验证从协调器接收的配置:
- 检查技术栈类型是否受支持(前端、后端.NET、后端Python)
- 验证版本是否有效(Node 18+、.NET 8+、Python 3.10+)
- 确认项目目录存在
输出: 验证通过的配置或错误信息
Phase 2: Template Selection
阶段2:模板选择
Select appropriate templates based on stack:
| Stack | Templates Used |
|---|---|
| Frontend only | dockerfile_frontend, nginx, dockerignore |
| Backend .NET | dockerfile_backend_dotnet, docker_compose, dockerignore |
| Backend Python | dockerfile_backend_python, docker_compose, dockerignore |
| Full stack .NET | All of the above (dotnet variant) |
| Full stack Python | All of the above (python variant) |
根据技术栈选择合适的模板:
| 技术栈 | 使用的模板 |
|---|---|
| 仅前端 | dockerfile_frontend、nginx、dockerignore |
| 后端.NET | dockerfile_backend_dotnet、docker_compose、dockerignore |
| 后端Python | dockerfile_backend_python、docker_compose、dockerignore |
| 全栈.NET | 上述所有模板(.NET版本) |
| 全栈Python | 上述所有模板(Python版本) |
Phase 3: Variable Substitution
阶段3:变量替换
Replace template variables with detected values:
| Variable | Source | Example |
|---|---|---|
| package.json engines or default | 22 |
| *.csproj TargetFramework | 9.0 |
| pyproject.toml or default | 3.12 |
| Directory name | my-app |
| *.csproj AssemblyName | MyApp.Api.dll |
| Default or detected | 3000 |
| Stack-dependent | 5000 (.NET), 8000 (Python) |
| Service name | backend |
| Framework-dependent | |
将模板中的变量替换为检测到的值:
| 变量 | 来源 | 示例 |
|---|---|---|
| package.json engines字段或默认值 | 22 |
| *.csproj文件的TargetFramework字段 | 9.0 |
| pyproject.toml文件或默认值 | 3.12 |
| 目录名称 | my-app |
| *.csproj文件的AssemblyName字段 | MyApp.Api.dll |
| 默认值或检测值 | 3000 |
| 技术栈相关 | 5000(.NET)、8000(Python) |
| 服务名称 | backend |
| 框架相关 | |
Phase 4: File Generation
阶段4:文件生成
Generate files from templates:
- Check if file already exists (warn before overwrite)
- Apply variable substitution
- Write file to appropriate location
- Validate syntax where possible
File Locations:
- ->
Dockerfile.frontendsrc/frontend/Dockerfile - -> project root
Dockerfile.backend - -> project root
docker-compose.yml - -> project root
.dockerignore - ->
nginx.confsrc/frontend/nginx.conf
根据模板生成文件:
- 检查文件是否已存在(覆盖前发出警告)
- 执行变量替换
- 将文件写入对应位置
- 尽可能验证语法正确性
文件位置:
- ->
Dockerfile.frontendsrc/frontend/Dockerfile - -> 项目根目录
Dockerfile.backend - -> 项目根目录
docker-compose.yml - -> 项目根目录
.dockerignore - ->
nginx.confsrc/frontend/nginx.conf
Supported Stacks
支持的技术栈
Frontend: React/Vite + Nginx
前端:React/Vite + Nginx
Requirements:
- package.json with build script
- Vite or CRA configuration
Generated:
- Multi-stage Dockerfile (builder + nginx)
- Nginx config with SPA routing and API proxy
要求:
- 包含build脚本的package.json文件
- Vite或CRA配置
生成内容:
- 多阶段构建Dockerfile(构建器 + nginx)
- 包含SPA路由和API代理的Nginx配置
Backend: .NET 8/9
后端:.NET 8/9
Requirements:
- *.sln file in root
- *.csproj with TargetFramework
Generated:
- Multi-stage Dockerfile (SDK build + ASP.NET runtime)
- Health check endpoint configuration
要求:
- 根目录下存在*.sln文件
- 包含TargetFramework字段的*.csproj文件
生成内容:
- 多阶段构建Dockerfile(SDK构建 + ASP.NET运行时)
- 健康检查端点配置
Backend: Python (FastAPI/Django)
后端:Python(FastAPI/Django)
Requirements:
- requirements.txt or pyproject.toml
Generated:
- Multi-stage Dockerfile (builder + slim runtime)
- uvicorn (FastAPI) or gunicorn (Django) entrypoint
要求:
- 存在requirements.txt或pyproject.toml文件
生成内容:
- 多阶段构建Dockerfile(构建器 + 轻量运行时)
- uvicorn(FastAPI)或gunicorn(Django)入口命令
Security & Performance Best Practices
安全与性能最佳实践
All generated files follow these guidelines:
| Practice | Implementation |
|---|---|
| Non-root user | Create and use appuser (UID 1001) |
| Minimal images | Alpine/slim variants |
| Multi-stage builds | Exclude build tools from runtime |
| No secrets | Use environment variables, not hardcoded |
| Health checks | Built-in HEALTHCHECK instructions (wget/curl) |
| Specific versions | Pin base image versions (e.g., nginx:1.27-alpine) |
| Non-interactive mode | ARG DEBIAN_FRONTEND=noninteractive |
| Layer caching | Copy dependency files first, source code last |
| BuildKit cache | Use |
| Python optimization | PYTHONDONTWRITEBYTECODE=1, PYTHONUNBUFFERED=1 |
所有生成的文件均遵循以下规范:
| 实践规范 | 实现方式 |
|---|---|
| 非root用户 | 创建并使用appuser用户(UID 1001) |
| 轻量级镜像 | 使用Alpine/slim版本镜像 |
| 多阶段构建 | 运行时镜像排除构建工具 |
| 无硬编码密钥 | 使用环境变量而非硬编码 |
| 健康检查 | 内置HEALTHCHECK指令(wget/curl) |
| 指定镜像版本 | 固定基础镜像版本(例如:nginx:1.27-alpine) |
| 非交互模式 | 设置ARG DEBIAN_FRONTEND=noninteractive |
| 分层缓存 | 先复制依赖文件,最后复制源代码 |
| BuildKit缓存 | 对pip使用 |
| Python优化 | 设置PYTHONDONTWRITEBYTECODE=1、PYTHONUNBUFFERED=1 |
Quality Criteria
质量标准
Generated files must meet:
- validates without errors
docker-compose config - All base images use specific versions (not )
latest - Non-root user configured in all Dockerfiles
- Health checks present for all services
- .dockerignore excludes all sensitive files
- No hardcoded secrets or passwords
生成的文件必须满足:
- 验证无错误
docker-compose config - 所有基础镜像均使用指定版本(而非)
latest - 所有Dockerfile均配置非root用户
- 所有服务均包含健康检查
- .dockerignore排除所有敏感文件
- 无硬编码密钥或密码
Critical Notes
重要说明
- Version Detection: Use detected versions from coordinator, not hardcoded defaults.
- Idempotent: Check file existence before writing. Warn if overwriting.
- Template-based: All generation uses templates from references/. Do NOT hardcode file contents.
- Security First: Every generated file must follow security best practices.
- 版本检测: 使用从协调器检测到的版本,而非硬编码的默认值。
- 幂等性: 写入前检查文件是否存在,覆盖前发出警告。
- 基于模板: 所有生成操作均使用references/目录下的模板,请勿硬编码文件内容。
- 安全优先: 所有生成的文件必须遵循安全最佳实践。
Reference Files
参考文件
| File | Purpose |
|---|---|
| dockerfile_frontend.template | React/Vite multi-stage Dockerfile |
| dockerfile_backend_dotnet.template | .NET multi-stage Dockerfile |
| dockerfile_backend_python.template | Python multi-stage Dockerfile |
| docker_compose.template | docker-compose.yml template |
| dockerignore.template | .dockerignore template |
| nginx.template | Nginx configuration |
Version: 1.2.0
Last Updated: 2026-01-21
| 文件 | 用途 |
|---|---|
| dockerfile_frontend.template | React/Vite多阶段构建Dockerfile |
| dockerfile_backend_dotnet.template | .NET多阶段构建Dockerfile |
| dockerfile_backend_python.template | Python多阶段构建Dockerfile |
| docker_compose.template | docker-compose.yml模板 |
| dockerignore.template | .dockerignore模板 |
| nginx.template | Nginx配置模板 |
版本: 1.2.0
最后更新时间: 2026-01-21