Write a compose.yaml for a web app with a database and cache: pinned images, health-checked startup order, private networking, named volumes and secrets kept out of the file.
Write a Docker Compose file for the multi-service application below. It must pass `docker compose config` and start services in a dependable order. Keep internal services off host ports unless a reason is given. ## Inputs Web service: language, framework, how it is built (Dockerfile path or image) and the port it listens on: [WEB_SERVICE] Database: engine and major version: [DATABASE] Cache or queue: engine and major version: [CACHE] Other services (workers, reverse proxy): [OTHER_SERVICES] Environment (local development, CI, single-host production): [ENVIRONMENT] Ports that must be reachable from the host: [HOST_PORTS] Configuration and secrets the services need: [CONFIGURATION] ## Instructions 1. Use the Compose Specification format. Omit the top-level `version` key; Docker documents it as obsolete. 2. Pin images to a specific version tag (and a digest for production) instead of `latest`. 3. Define a custom network (for example `app-net`) and attach every service. Services reach each other by service name. 4. Persist database data in a named volume. Do not persist cache data unless the cache is also used as a durable queue. 5. Add `healthcheck` blocks to the database and cache, and use `depends_on` with `condition: service_healthy` for the web service. 6. Publish only [HOST_PORTS]. The database and cache stay internal unless listed. 7. Pass the database connection settings to the web service as environment variables, reading values from an `.env` file or Compose secrets; do not write real passwords in the file. 8. Set `restart` policies appropriate to [ENVIRONMENT]. ## Return 1. The complete `compose.yaml`. 2. An `.env.example` listing every variable with placeholder values. 3. Commands to validate (`docker compose config`), start, view logs and stop. 4. Notes on what changes for production on a single host versus local development. ## Acceptance checks - `docker compose config` accepts the file. - No `latest` tags and no top-level `version` key. - No real secrets in `compose.yaml` or `.env.example`. - Only the requested ports are published to the host.
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Web: Python 3.12 Flask app built from ./Dockerfile, gunicorn listening on 8000 Database: PostgreSQL 17 Cache: Redis 7 Other services: none Environment: local development Host ports: web only, mapped to host port 8080 Configuration: DATABASE_URL, REDIS_URL, SECRET_KEY
A compose.yaml with services web, db and cache on network app-net; images postgres:17 and redis:7 (pinned major or minor tags); a named volume db-data mounted at /var/lib/postgresql/data; pg_isready and redis-cli ping healthchecks; web depends_on db and cache with condition: service_healthy; only "8080:8000" published; DATABASE_URL and REDIS_URL built from variables in .env; no top-level version key. A reference file of this shape passed `docker compose config -q` locally (see report); the model's own output was not run.
Ask questions or share concrete improvements.
No comments yet.
Sign in to join the discussion.
Guides for adapting and checking prompts: