返回提示词目录第 1185 页

生成项目开发容器配置

读取项目依赖与运行要求,生成开发容器及配套服务配置,说明环境变量、首次启动步骤和验证状态。

完整提示词

<context>
A dev container should give a new contributor a working environment from one click, but common configs are slow and fragile: every rebuild reinstalls everything because steps that change often sit early in the Dockerfile; tools are installed by piping unpinned remote install scripts into a shell instead of using dev container Features; the container runs as root so files created in the bind-mounted workspace end up root-owned on the host; dependency folders are installed inside the bind mount, which is very slow on macOS and Windows; and services like databases are crammed into the same container. Use an official base image (`mcr.microsoft.com/devcontainers/<language>` with a version tag), Features for CLIs, `remoteUser` set to the non-root user, `postCreateCommand` for dependency installs, a named volume for heavy dependency directories, and Docker Compose when services are needed. Codespaces adds machine size (`hostRequirements`), prebuilds, and secrets that arrive as environment variables.
</context>

<task>
Write a dev container setup for {{tool}}:
{{project}}

1. Read the repository first: runtime version files, dependency manifests and lockfiles, the scripts used to build, test and lint, existing Dockerfiles or compose files, `.vscode/extensions.json` and settings, and the README setup steps. Reuse what exists and match versions exactly.
2. Choose single container or Docker Compose (needed when the project uses a database, cache or queue) and say why.
3. Write `.devcontainer/devcontainer.json`: `name`, base image or build or compose reference, Features with pinned major versions for extra CLIs, `remoteUser` non-root, `forwardPorts` with labels, `customizations.vscode.extensions` and minimal settings, `postCreateCommand` that installs dependencies with the lockfile, `mounts` for a named volume over heavy dependency directories where useful, and `hostRequirements` for Codespaces if the build needs memory.
4. If a Dockerfile is needed, order layers from least to most often changed, pin versions, and clean package caches.
5. If compose is used, give services health checks, pinned images and named volumes, with the app container waiting for them.
6. Environment: list required environment variables, provide a `.env.example` or Codespaces secrets list, and never write real values.
7. If the dev container CLI is available, build it and run the project's test command inside; otherwise say it was not run.
</task>

<constraints>
- Only use Features and base images you are confident exist; mark any you are unsure of.
- No secrets or tokens in any file.
- Do not change the project's own build files or scripts; only add `.devcontainer/` files and the env example.
{{> guardrails/verify-before-done}}
</constraints>

<output_format>
## Assumptions
Bullets, including versions matched from the repo.
## Files
Fenced blocks with paths: `devcontainer.json`, and the Dockerfile and compose file if used.
## First run
Steps for VS Code and for Codespaces, and how long the first build is expected to take relative to rebuilds.
## Gaps
Anything that differs from production or from the team's local setup, and verification status.
</output_format>

可替换内容

  • {{tool}}
  • {{project}}
  • {{> guardrails/verify-before-done}}

分类与标签

编程开发、开发容器、环境配置、容器编排、云端开发

前往 AI 图片创作