ln-731-docker-generator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

ln-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

输入项

InputSourceDescription
Stack Typeln-730 coordinatorfrontend, backend-dotnet, backend-python
VersionsAuto-detectedNode.js, .NET, Python versions
Project NameDirectory nameUsed for container naming
PortsDefaults or detectedFrontend: 3000, Backend: 5000/8000, DB: 5432

输入项来源描述
技术栈类型ln-730 协调器前端、后端.NET、后端Python
版本信息自动检测Node.js、.NET、Python版本
项目名称目录名称用于容器命名
端口配置默认值或自动检测前端:3000,后端:5000/8000,数据库:5432

Outputs

输出项

FilePurposeTemplate
Dockerfile.frontend
Frontend build & servedockerfile_frontend.template
Dockerfile.backend
Backend build & rundockerfile_backend_dotnet.template or dockerfile_backend_python.template
docker-compose.yml
Service orchestrationdocker_compose.template
.dockerignore
Build context exclusionsdockerignore.template
nginx.conf
Frontend proxy confignginx.template

文件用途模板
Dockerfile.frontend
前端构建与服务部署dockerfile_frontend.template
Dockerfile.backend
后端构建与运行dockerfile_backend_dotnet.templatedockerfile_backend_python.template
docker-compose.yml
服务编排docker_compose.template
.dockerignore
构建上下文排除规则dockerignore.template
nginx.conf
前端代理配置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:
StackTemplates Used
Frontend onlydockerfile_frontend, nginx, dockerignore
Backend .NETdockerfile_backend_dotnet, docker_compose, dockerignore
Backend Pythondockerfile_backend_python, docker_compose, dockerignore
Full stack .NETAll of the above (dotnet variant)
Full stack PythonAll of the above (python variant)
根据技术栈选择合适的模板:
技术栈使用的模板
仅前端dockerfile_frontend、nginx、dockerignore
后端.NETdockerfile_backend_dotnet、docker_compose、dockerignore
后端Pythondockerfile_backend_python、docker_compose、dockerignore
全栈.NET上述所有模板(.NET版本)
全栈Python上述所有模板(Python版本)

Phase 3: Variable Substitution

阶段3:变量替换

Replace template variables with detected values:
VariableSourceExample
{{NODE_VERSION}}
package.json engines or default22
{{DOTNET_VERSION}}
*.csproj TargetFramework9.0
{{PYTHON_VERSION}}
pyproject.toml or default3.12
{{PROJECT_NAME}}
Directory namemy-app
{{DLL_NAME}}
*.csproj AssemblyNameMyApp.Api.dll
{{FRONTEND_PORT}}
Default or detected3000
{{BACKEND_PORT}}
Stack-dependent5000 (.NET), 8000 (Python)
{{BACKEND_HOST}}
Service namebackend
{{CMD}}
Framework-dependent
["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
(FastAPI) or
["gunicorn", "--bind", "0.0.0.0:8000", "{{PROJECT_NAME}}.wsgi:application"]
(Django)
将模板中的变量替换为检测到的值:
变量来源示例
{{NODE_VERSION}}
package.json engines字段或默认值22
{{DOTNET_VERSION}}
*.csproj文件的TargetFramework字段9.0
{{PYTHON_VERSION}}
pyproject.toml文件或默认值3.12
{{PROJECT_NAME}}
目录名称my-app
{{DLL_NAME}}
*.csproj文件的AssemblyName字段MyApp.Api.dll
{{FRONTEND_PORT}}
默认值或检测值3000
{{BACKEND_PORT}}
技术栈相关5000(.NET)、8000(Python)
{{BACKEND_HOST}}
服务名称backend
{{CMD}}
框架相关
["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
(FastAPI)或
["gunicorn", "--bind", "0.0.0.0:8000", "{{PROJECT_NAME}}.wsgi:application"]
(Django)

Phase 4: File Generation

阶段4:文件生成

Generate files from templates:
  1. Check if file already exists (warn before overwrite)
  2. Apply variable substitution
  3. Write file to appropriate location
  4. Validate syntax where possible
File Locations:
  • Dockerfile.frontend
    ->
    src/frontend/Dockerfile
  • Dockerfile.backend
    -> project root
  • docker-compose.yml
    -> project root
  • .dockerignore
    -> project root
  • nginx.conf
    ->
    src/frontend/nginx.conf

根据模板生成文件:
  1. 检查文件是否已存在(覆盖前发出警告)
  2. 执行变量替换
  3. 将文件写入对应位置
  4. 尽可能验证语法正确性
文件位置:
  • Dockerfile.frontend
    ->
    src/frontend/Dockerfile
  • Dockerfile.backend
    -> 项目根目录
  • docker-compose.yml
    -> 项目根目录
  • .dockerignore
    -> 项目根目录
  • nginx.conf
    ->
    src/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:
PracticeImplementation
Non-root userCreate and use appuser (UID 1001)
Minimal imagesAlpine/slim variants
Multi-stage buildsExclude build tools from runtime
No secretsUse environment variables, not hardcoded
Health checksBuilt-in HEALTHCHECK instructions (wget/curl)
Specific versionsPin base image versions (e.g., nginx:1.27-alpine)
Non-interactive modeARG DEBIAN_FRONTEND=noninteractive
Layer cachingCopy dependency files first, source code last
BuildKit cacheUse
--mount=type=cache
for pip
Python optimizationPYTHONDONTWRITEBYTECODE=1, PYTHONUNBUFFERED=1

所有生成的文件均遵循以下规范:
实践规范实现方式
非root用户创建并使用appuser用户(UID 1001)
轻量级镜像使用Alpine/slim版本镜像
多阶段构建运行时镜像排除构建工具
无硬编码密钥使用环境变量而非硬编码
健康检查内置HEALTHCHECK指令(wget/curl)
指定镜像版本固定基础镜像版本(例如:nginx:1.27-alpine)
非交互模式设置ARG DEBIAN_FRONTEND=noninteractive
分层缓存先复制依赖文件,最后复制源代码
BuildKit缓存对pip使用
--mount=type=cache
Python优化设置PYTHONDONTWRITEBYTECODE=1、PYTHONUNBUFFERED=1

Quality Criteria

质量标准

Generated files must meet:
  • docker-compose config
    validates without errors
  • 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

重要说明

  1. Version Detection: Use detected versions from coordinator, not hardcoded defaults.
  2. Idempotent: Check file existence before writing. Warn if overwriting.
  3. Template-based: All generation uses templates from references/. Do NOT hardcode file contents.
  4. Security First: Every generated file must follow security best practices.

  1. 版本检测: 使用从协调器检测到的版本,而非硬编码的默认值。
  2. 幂等性: 写入前检查文件是否存在,覆盖前发出警告。
  3. 基于模板: 所有生成操作均使用references/目录下的模板,请勿硬编码文件内容。
  4. 安全优先: 所有生成的文件必须遵循安全最佳实践。

Reference Files

参考文件

FilePurpose
dockerfile_frontend.templateReact/Vite multi-stage Dockerfile
dockerfile_backend_dotnet.template.NET multi-stage Dockerfile
dockerfile_backend_python.templatePython multi-stage Dockerfile
docker_compose.templatedocker-compose.yml template
dockerignore.template.dockerignore template
nginx.templateNginx configuration

Version: 1.2.0 Last Updated: 2026-01-21
文件用途
dockerfile_frontend.templateReact/Vite多阶段构建Dockerfile
dockerfile_backend_dotnet.template.NET多阶段构建Dockerfile
dockerfile_backend_python.templatePython多阶段构建Dockerfile
docker_compose.templatedocker-compose.yml模板
dockerignore.template.dockerignore模板
nginx.templateNginx配置模板

版本: 1.2.0 最后更新时间: 2026-01-21