Create a multi-stage Dockerfile, .dockerignore and development/production Compose files for a single application, with non-root runtime, health checks and cache-friendly layers.
You are a DevOps engineer. Containerize the single application below. Produce a Dockerfile that builds a small, non-root runtime image, plus Compose files for development and production. Multi-service architecture design is out of scope. ## Inputs Application type (web app, API, worker): [APP_TYPE] Language, framework and version: [STACK] Dependency manifest and lock file (for example package-lock.json, poetry.lock): [DEPENDENCY_FILES] Build, start and test commands: [COMMANDS] Port and health endpoint: [PORT_AND_HEALTH] Environments needed (development, production, or both): [ENVIRONMENTS] Required environment variables (names only): [ENV_VARS] ## Instructions 1. Write a multi-stage Dockerfile: dependency install, build, and a minimal runtime stage. Pin the base image to a version tag. 2. Order layers for caching: copy dependency manifests and install before copying the source. 3. Run as a non-root user in the runtime stage, and copy only build outputs and production dependencies into it. 4. Add a HEALTHCHECK that uses [PORT_AND_HEALTH] with a tool that exists in the runtime image, or explain why the orchestrator's health check is used instead. 5. Write a `.dockerignore` that excludes version control data, local environment files, dependency folders and build outputs. 6. Development Compose file: bind-mount source for hot reload. Production overrides: no bind mounts, restart policy, resource limits if the host needs them. 7. Read configuration from environment variables; never bake secrets into the image. ## Return 1. `Dockerfile` 2. `.dockerignore` 3. `compose.yaml` (development) 4. `compose.prod.yaml` (production overrides) 5. Commands: `docker build`, `docker compose up`, and `docker compose -f compose.yaml -f compose.prod.yaml up -d` 6. Explanation of the size, caching and security choices, and anything to verify for this stack. ## Acceptance checks - The runtime stage has a non-root `USER`. - Dependency install comes before copying application source. - No secret values in the Dockerfile or Compose files. - Base images are pinned; commands use the `docker compose` CLI form.
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Type: web app Stack: Next.js 15 on Node 22, npm, output: 'standalone' enabled in next.config.ts Dependency files: package.json, package-lock.json Commands: npm ci; npm run build; node server.js (from .next/standalone) Port/health: 3000, GET /api/health returns 200 Environments: both Env vars: DATABASE_URL, NEXTAUTH_SECRET
A Dockerfile with deps (npm ci), builder (npm run build) and runner stages based on a pinned node:22 slim or alpine tag; the runner copies .next/standalone, .next/static and public, sets USER node and runs node server.js on port 3000; a HEALTHCHECK using node to request /api/health because curl may not exist in the slim image; a .dockerignore excluding .git, node_modules, .next and .env*; a development compose.yaml with a bind mount and npm run dev; and compose.prod.yaml with restart: unless-stopped and no bind mounts. Illustrative expectation, not a recorded model run.
Ask questions or share concrete improvements.
No comments yet.
Sign in to join the discussion.
Guides for adapting and checking prompts:
Author-supplied tool and model tags; confirm behavior with your own examples.
IDEs
Models