Structuring your compose file
A normal docker-compose.yml works. A few things behave differently from docker compose up on your laptop, and knowing them up front saves a redeploy.
A complete example
Section titled “A complete example”services: web: image: ghcr.io/acme/shop:1.4.2 ports: - "3000" # published: gets a public HTTPS address environment: DATABASE_URL: postgres://shop@db:5432/shop STRIPE_KEY: # blank: filled in from the project's env vars depends_on: - db deploy: resources: limits: cpus: "0.5" memory: 512M
db: image: postgres:17 volumes: - pgdata:/var/lib/postgresql/data environment: POSTGRES_USER: shop POSTGRES_PASSWORD: # from the project's env vars stop_grace_period: 60s deploy: resources: limits: cpus: "1" memory: 1G x-cargoforge: storage_limit_gb: 10
volumes: pgdata:Images
Section titled “Images”Every service needs an image: from a registry (Docker Hub, GHCR, …). build: only works for a project connected to GitHub or GitLab: each push builds the image from your repo.
Ports and addresses
Section titled “Ports and addresses”- Each published port (
ports:) gets its own public hostname with HTTPS, shown under the project’s Endpoints. The host side of"8080:80"is ignored; only the container port (80) matters. - Unpublished services (like
dbabove) aren’t reachable from the internet at all, only by the other services of the same project. - Services reach each other by service name:
db:5432. (Images with no shell, such as distroless orscratch, can be reached by name but can’t look names up themselves.) - While a service is starting and not answering on its port yet, visitors see a “Starting” page instead of an error, for up to 10 minutes.
Sizing
Section titled “Sizing”Set a limit per service, either deploy.resources.limits (cpus, memory) or the short cpus / mem_limit. A service gets exactly its limit, and that’s what it’s billed on. With no limit it gets 0.5 vCPU and 1 GB. Details and maximums: Directives.
Anything that must survive a redeploy goes in a named volume (pgdata:/var/lib/postgresql/data), never a host path. See Volumes and storage.
Secrets
Section titled “Secrets”Keep them out of the file: set them as project environment variables and leave the key blank (or out) in environment:. See Environment variables.
Order and restarts
Section titled “Order and restarts”depends_onis honoured for start order.restart:is honoured. A service that keeps crashing marks the deployment degraded, and after 15 minutes it’s stopped so it doesn’t loop forever; fix it and redeploy or restart it.- Services behind
profiles:are not deployed (no profile is ever activated).