Example result: Review and improve a Dockerfile
AI-generated example · Dockerfile Review
Updated

Review and improve a Dockerfile

This prompt reviews a Dockerfile for an app type and language, and suggests improvements.

text-dockerfile-review — chatgpt — 43 words

Review this Dockerfile:

[PASTE DOCKERFILE]

The app: [APP TYPE AND LANGUAGE]

Check for security issues, image size, build caching, unnecessary layers, running as root and missing health checks. Provide an improved version with comments explaining every change and any behaviour I should test.

Ask for the image size before and after to see how much the changes really save.

Get a better result

What you will get

A review of your Dockerfile covering security, image size, build caching, extra layers, running as root and health checks, then an improved version with a comment on each change and what to test.

Why it works

Dockerfiles quietly collect problems: running as root, large images and cache-busting layer order. The prompt lists each of those so the review is complete, and asks for comments on every change so you understand them. Asking what behaviour to test matters because many improvements change how the container runs.

Common mistake

The new base image breaks your app.

Fix: Switching to a slim or Alpine image can remove libraries you need. Build and run the tests before you merge.

Also watch for
  • The non-root user cannot write where the app needs to. Check folders the app writes to, such as logs or uploads, and give that user permission.
  • You cannot tell how much it saved. Ask for the image size before and after, as the tip says, and check it yourself with your build.
Try a variation: compose file

Paste your compose file too and ask for a review of ports, secrets in environment variables and restart policies.

Still not right? Reply with this

Split the improved file into a multi-stage build that keeps build tools out of the final image, and explain what each stage copies.

More chat & writing prompts

See all 465 →