5.2 KiB
5.2 KiB
Docker Compose Repository Guidelines
Compose Anything is a collection of production-ready, portable Docker Compose stacks. The default experience should remain simple: users should be able to enter a service directory and start it with docker compose up -d, while still getting sensible defaults for resource limits, health checks, security, and documentation.
Primary Goals
- Keep every stack easy to start and easy to understand.
- Prefer portable Compose patterns that work across Windows, macOS, and Linux.
- Default to production-aware settings instead of demo-only shortcuts.
- Keep service documentation and root indexes accurate whenever a service changes.
Required Workflow For Service Changes
- Read the existing service folder before editing anything.
- Use the repo root
.compose-template.yamlas the structural reference when applicable. - Update these files together when a service changes:
docker-compose.yaml,.env.example,README.md, andREADME.zh.md. - Update the root
README.mdandREADME.zh.mdwhenever a service is added, renamed, removed, or needs a new quick-start entry. - Keep the default startup path within
docker compose up -d. If extra setup is unavoidable, document it clearly and prefer aMakefileover ad-hoc instructions.
Compose Standards
- Out-of-the-box startup
- A stack should work with zero extra steps, except optionally creating a
.envfile from.env.example. - Defaults must be usable for local evaluation without forcing users to edit configuration first.
- A stack should work with zero extra steps, except optionally creating a
- Command simplicity
- Each project should ship a single
docker-compose.yamlfile. - Initialization order should use
healthcheckplusdepends_on.condition: service_healthywhenever a dependency chain exists.
- Each project should ship a single
- Version pinning
- Pin to a stable image version instead of
latestwhenever a stable tag exists. - Expose image versions via environment variables such as
REDIS_VERSIONorPOSTGRES_VERSION.
- Pin to a stable image version instead of
- Configuration style
- Prefer environment variables over long CLI flags.
- Never hardcode secrets.
- Provide a fully commented
.env.examplein English. - Use UPPER_SNAKE_CASE names with a service prefix.
- Use
*_PORT_OVERRIDEfor host port overrides.
- Profiles
- Use Compose profiles for optional components only.
- Preferred profile names:
gpu,metrics,dev.
- Cross-platform support
- Favor patterns that work on Debian 12+, Ubuntu 22.04+, Windows 10+, and macOS 12+ when upstream images support them.
- Support both x86-64 and ARM64 as consistently as practical.
- Avoid Linux-only host paths such as
/etc/localtime; preferTZ.
- Storage and mounts
- Prefer named volumes for application data.
- Prefer relative paths for repo-managed configuration files.
- If host paths are necessary, expose a top-level directory variable such as
DATA_DIR.
- Resources and logging
- Every service must define CPU and memory limits.
- GPU services should default to one GPU via
deploy.resources.reservations.devicesorgpus. - Limit container logs with the
json-filedriver andmax-size/max-file.
- Health checks
- Every long-running service should define a meaningful
healthcheck. - Tune
interval,timeout,retries, andstart_periodfor the actual startup profile of the service.
- Every long-running service should define a meaningful
- Security baseline
- Run as non-root when practical.
- Use
read_only: trueplus writable mounts ortmpfswhere feasible. - Default to
cap_drop: ["ALL"]and add back only what is required. - Do not use
container_name. - If a stack requires the Docker socket or another high-risk mount, document the risk and safer alternatives.
Documentation Standards
- Every service must provide both
README.mdandREADME.zh.md. - Service READMEs should at minimum cover: purpose, services, quick start, key environment variables, storage, and security notes when relevant.
- The root
README.mdandREADME.zh.mdshould remain useful as entry points, not just service indexes. Include concise quick-start guidance and at least one concrete example when it helps discovery. - List the main environment variables and default ports in the service README.
- Keep documentation LLM-friendly: predictable headings, short paragraphs, and concrete command examples.
Reference template: /.compose-template.yaml
If you need image tags, check the Docker Hub API, for example:
https://hub.docker.com/v2/repositories/library/nginx/tags?page_size=1&ordering=last_updated
Final Checklist
- Is
.env.examplepresent and fully commented in English? - Are CPU and memory limits defined?
- Has
container_namebeen avoided or removed? - Are
healthcheckanddepends_on.condition: service_healthyused correctly? - Are
README.mdandREADME.zh.mdboth updated for the service? - Are the root
README.mdandREADME.zh.mdupdated if discoverability changed? - Are Chinese docs using Chinese punctuation, with spaces between Chinese and English terms?
注意:所有中文文档都使用中文标点,如 “,”、“()” 等,中文与英文之间保留空格。Docker Compose 文件和 .env.example 文件中的注释必须使用英文。每个服务都必须提供英文 README.md 和中文 README.zh.md。