Docker Compose
Encyclopedia home · Search machine-readable catalog
CF-011
Local app with loopback port
Copy to compose.yml.
services:
web:
build: .
ports: ["127.0.0.1:18000:8000"]Verification. Run docker compose up --build and test localhost:18000.
Validation syntax-validated. Official reference
CF-012
PostgreSQL readiness
Copy to compose.yml.
services:
db:
image: postgres:16-alpine
environment: {POSTGRES_PASSWORD: disposable-test-only}
healthcheck:
test: ["CMD-SHELL","pg_isready -U postgres"]
interval: 2s
timeout: 2s
retries: 10Verification. The test password is isolated to the disposable network. Do not publish this service.
Validation syntax-validated. Official reference
CF-013
Redis integration dependency
Copy to compose.yml.
services:
cache:
image: redis:7-alpine
healthcheck:
test: ["CMD","redis-cli","ping"]
interval: 2s
timeout: 2s
retries: 10Verification. Wait with compose up --wait. Assert cache:6379 from containers.
Validation syntax-validated. Official reference
CF-014
Service-health dependency order
Copy to compose.override.yml.
services:
web:
depends_on:
db: {condition: service_healthy}Verification. Merge with base files defining web and db. Tests should still handle DB restarts.
Validation syntax-validated. Official reference
CF-015
Test-only service profile
Copy to compose.yml.
services:
checks:
image: python:3.12-slim
working_dir: /src
volumes: [".:/src:ro"]
profiles: ["test"]
command: ["python","-m","unittest","discover","-s","tests"]Verification. Use docker compose --profile test run --rm checks and retain its exit status.
Validation syntax-validated. Official reference
CF-016
Read-only app container
Copy to compose.yml.
services:
web:
build: .
read_only: true
tmpfs: ["/tmp:size=16777216"]
cap_drop: [ALL]
security_opt: ["no-new-privileges:true"]Verification. Smoke-test an image that writes only to /tmp. Restrict caps deliberately.
Validation syntax-validated. Official reference
CF-017
Environment example file injection
Copy to compose.yml.
services:
web:
build: .
env_file: [.env.ci.example]Verification. Use non-secret placeholders in checked-in example files and validate generated defaults.
Validation syntax-validated. Official reference
CF-018
Internal database network
Copy to compose.yml.
services:
db:
image: postgres:16-alpine
environment: {POSTGRES_PASSWORD: disposable-test-only}
networks: [internal]
networks:
internal: {internal: true}Verification. Only attach app peers that need DB access. Do not publish ports.
Validation syntax-validated. Official reference
CF-019
Mount a file-based secret
Copy to compose.yml.
services:
web:
build: .
secrets: [api_token]
secrets:
api_token: {file: "./.local/api-token"}Verification. Provision outside version control. App reads /run/secrets/api_token.
Validation syntax-validated. Official reference
CF-020
Reverse-proxy service config
Copy to compose.yml.
services:
gateway:
image: nginx:1.27-alpine
ports: ["127.0.0.1:18080:80"]
volumes: ["./proxy.conf:/etc/nginx/conf.d/default.conf:ro"]
web:
build: .Verification. Supply proxy.conf pointing at web:8000. Test host access through port 18080 only.
Validation syntax-validated. Official reference