c/devops › command
0votes

Write a minimal production Dockerfile

PromptLow risk Tested
submitted by CommandVault editors to c/devops · 1 use

Small, cached, non-root images for any app.

Prompt · 3 variables
Write a production Dockerfile for a {{language}} app whose start command is {{start_command}}.

Requirements:
- Multi-stage build; final image based on a slim or distroless base.
- Dependency install layer cached separately from source.
- Runs as a non-root user.
- Only production dependencies in the final image.
- HEALTHCHECK if the app exposes HTTP on {{port}}.
- A matching .dockerignore.

Explain the expected final image size and how to verify it.
0 commentsreport

Guide

What you get: You get a multi-stage Dockerfile and .dockerignore: cached dependency layer, production dependencies only, non-root user, HTTP HEALTHCHECK, plus an image-size estimate and how to verify it. Best for Developers containerising a web app for production..

Before you start

  • Fill language, start_command and port (we used Node.js 22 + TypeScript built into dist/, node dist/server.js, 3000 with GET /healthz)
  • Docker to build and check the image yourself

Worked example (Nov 14, 2026, Claude Code 2.1.318 (claude-opus-5-5); Codex 0.151.0 (gpt-5.6-sol))

Input

bakehouse-api (Express 5 + TypeScript, npm run build -> dist/, GET /healthz).

Result

Claude Code: final stage `gcr.io/distroless/nodejs22-debian12:nonroot`, HEALTHCHECK via Node fetch, allowlist .dockerignore. Codex: final stage `node:22-bookworm-slim` with `USER node`, HEALTHCHECK via Node fetch, denylist .dockerignore.

Neither tool could run Docker in its session; we built and ran both images. Both built, served /healthz, reached Docker health status 'healthy', ran as non-root (uid 65532 / 1000) and contained only express and zod (no typescript, vitest, tsx, oxlint). Sizes: Claude Code 173 MB uncompressed / 54 MB saved (it estimated 135-150 MB / 45-55 MB); Codex 279 MB / 82 MB (it estimated 220-260 MiB / 60-90 MB). Both chown the app files to the runtime user, so the app can modify its own code; not a stated requirement.

How to check it worked

  • docker build, then docker run and wait for health status 'healthy'
  • docker exec <container> id -u (or node -e 'console.log(process.getuid())' on distroless) should not be 0
  • List node_modules in the image: no dev dependencies

Common problems

  • curl/wget-based HEALTHCHECK on slim or distroless images that don't have them (both tools avoided this)
  • Distroless images have no shell, so `docker exec ... sh` debugging doesn't work

Try it here

Fill in {{language}}, {{start_command}}, {{port}} above first for a better answer, or run it as is and the AI will assume sensible values.

or open in ChatGPT · Claude · Perplexity

How to use this prompt

  1. Fill in the 3 blanks above. The more specific you are, the better the answer.
  2. Copy it and paste it into ChatGPT, Claude, Gemini, Cursor or Codex, or use "Try it here" for a quick test.
  3. Read the answer critically: check anything it claims about your code or data before you rely on it.
  • {{language}} Language
  • {{start_command}} Start command
  • {{port}} Port

More from c/devops

See all of c/devops →
0 comments

Log in to join the discussion.