1. Home
  2. Developer tools
  3. Dockerfile Generator

Dockerfile Generator

Get a small, cache-friendly production image without learning every Dockerfile trick first, and catch the classic mistakes in Dockerfiles you already have.

Free, no sign-up. Runs in your browser: nothing is uploaded.

How to use Dockerfile Generator

  1. Pick the stack and fill in version, port and commands.
  2. Choose Alpine and non-root options.
  3. Download Dockerfile and .dockerignore, or paste an existing Dockerfile to check it.

Features

  • Templates for Node (npm, pnpm, Yarn), Python, Go, Rust, Java and Nginx static sites
  • Lockfile copied before source so dependency layers stay cached
  • Distroless or slim runtime images and a non-root USER
  • Optional HEALTHCHECK and JSON-form CMD
  • Checker for unpinned images, apt-get cleanup, shell-form CMD, secrets in ENV and more

Supported formats

Input

  • Form input

You get

  • DOCKERFILE

Private by design

Everything you enter is processed by your browser on this device. Nothing is sent to openWorkstand or anyone else, so the Dockerfile Generator is safe for private and work data. After you have used it once while online, it also works without an internet connection. How local processing works

Good to know

  • Templates assume a conventional project layout (lockfile at the root, build output in dist or target); adjust paths for monorepos.
  • The checker covers common rules, not every hadolint rule.

Guide

Multi-stage Dockerfiles that build fast and ship small

A Dockerfile that works is easy to write; one that rebuilds in seconds, produces a small image and does not run as root takes a few patterns most people learn the hard way. This generator writes multi-stage Dockerfiles that follow those patterns for six common stacks, along with a .dockerignore, and checks Dockerfiles you already have.

Layers and caching

Docker builds an image as a stack of layers, one per instruction, and reuses a cached layer as long as the instruction and its inputs have not changed. Order matters: if COPY . . comes before installing dependencies, every code change invalidates the install layer and the next build downloads everything again. The templates copy only the lockfile first, install, and copy the rest of the source afterwards.

Multi-stage builds

Each template has at least two FROM lines. The first stages install build tools and compile or bundle the app. The final stage starts again from a small runtime image and copies in only what the app needs to run. For Go, that runtime is distroless static, which contains no shell at all; for Java the build uses a JDK and the runtime a JRE; for a static site the build uses Node and the runtime is Nginx serving the dist folder.

The stack templates

The Node template supports npm, pnpm and Yarn through corepack and installs production dependencies again in the runtime stage. Python builds a virtual environment in one stage and copies it into a clean image, setting PYTHONUNBUFFERED so logs appear immediately. Rust compiles a dummy main.rs first so dependencies are cached separately from your code. Each template sets the port, the start command in JSON form and an optional HEALTHCHECK.

Base images and users

Slim Debian images are the default because they use glibc, which prebuilt native packages expect. The Alpine option gives smaller images using musl, which can break some binary wheels and Node modules, so test before switching. With “Run as a non-root user” on, the template uses the image’s existing node user, creates an unprivileged user, or picks a nonroot variant, so a compromised process cannot modify the image’s system files.

A worked example

With the Node defaults, the file starts with a deps stage FROM node:22-slim AS deps, installs with npm ci, builds in a second stage and creates a runtime stage that runs npm ci --omit=dev, copies dist, switches to USER node, exposes 3000 and starts with CMD ["node","dist/server.js"]. Switching to Go gives a final stage FROM gcr.io/distroless/static-debian12:nonroot. Pasting FROM node, COPY . ., RUN npm install and CMD npm start into the checker returns four suggestions: pin a tag, install dependencies before copying the source, use the JSON form of CMD and add a non-root user.

The checker

The checker reads an existing Dockerfile line by line and reports common problems: unpinned or latest images, apt-get install without --no-install-recommends or without cleaning the package lists, apt-get update in its own layer, ADD used for local files, shell-form CMD, sudo, RUN cd, secrets set with ENV, and the lack of any USER instruction. It covers frequent hadolint rules, not all of them.

Assumptions

Templates assume the lockfile sits at the project root and the build writes to dist or target. Monorepos and unusual layouts need the paths adjusted. Always build and run the image once locally before relying on it.

Checked against the current version of the Dockerfile Generator on .

Frequently asked questions

What does the syntax line at the top do?

The # syntax=docker/dockerfile:1 comment tells BuildKit to use the latest stable version of the Dockerfile frontend, which enables features such as RUN --mount for caches and secrets regardless of the Docker version installed.

Why is the final image so much smaller than the build stage?

The final stage starts from a fresh, slim base and copies in only the build output and production dependencies. Compilers, dev dependencies, source files and caches from the build stage never reach it, which often cuts the image from over a gigabyte to a few hundred megabytes or less.

Why copy package.json before the rest of the code?

Docker caches each layer until its inputs change. If the dependency install only depends on the lockfile, editing your code does not trigger a full reinstall, which turns minute-long rebuilds into seconds.

Alpine or slim?

Alpine images are smaller but use musl instead of glibc, which can break prebuilt native modules (some Python wheels, sharp, Prisma engines). Debian slim is a safer default; choose Alpine when you have tested your dependencies on it.

Keep working with the result

openWorkstand also includes a free workspace with documents, spreadsheets, tasks, projects and a calendar that save to a folder on your computer.