agent-ready Compose guide
Deploy an AI-Generated Docker Compose File
Turn a Compose file generated by an AI coding agent into a production deployment with validation, guardrails, and Defang.
An AI-generated Compose file is useful when it becomes a reviewed deployment contract. The deployment path should be simple: validate the file, make production intent explicit, then deploy with Defang.
Step 1: Validate the file
Use compose.new to inspect the service graph and check the Compose structure. Make sure the file reflects the actual app, not just the agent’s guess.
Step 2: Add production guardrails
Add health checks, remove embedded secrets, confirm public ports, and use managed-service annotations when the app needs databases, caches, or model access. Declare service dependencies with depends_on when startup order matters.
services:
api:
build: .
ports:
- "8080:8080"
environment:
- QUEUE_URL
- DATABASE_URL
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3
depends_on:
db:
condition: service_started
worker:
build: .
command: npm run worker
environment:
- QUEUE_URL
depends_on:
db:
condition: service_started
db:
image: postgres:17
x-defang-postgres: true
Note: The
imagefield (e.g.,postgres:17) is required — Defang uses it to determine the managed service version. Locally,docker compose upuses the same image as a regular container. Thex-defang-annotations are only interpreted by Defang during cloud deployment.
Step 3: Deploy with Defang
defang login
defang stack new # interactive: select provider, region, name the stack
defang compose up
Store sensitive values with defang config set SECRET_NAME.
Use Defang Agent Skills
Install Defang Agent Skills if you want a compatible coding agent to help with Defang’s estimate, deploy, and debug workflows after the Compose file is validated.
Why this is review-friendly
Your agent edits a single file. You review a single file. Defang handles the cloud-specific deployment work after the deployment shape is clear. That is easier to audit than large generated infrastructure definitions before the app has proven its deployment shape.
Practical workflow
Validate the AI-generated Compose file in compose.new. Keep the deployment intent visible. Deploy the reviewed file with Defang.