Dockerfile Generator
Build a Dockerfile from a form. Supports multi-stage builds, env vars, healthchecks, and inline best-practice hints.
Client-side only — nothing leaves your browser
Image
Pin a specific tag. Avoid :latest in production.
Copy lockfiles before source so dependency installs cache better.
Blank lines separate RUN layers. Lines in one block are joined with && \\ to keep them in a single layer.
Space- or comma-separated. e.g. 80 443, 53/udp
Run as a non-root user in production
The default command to run.
FROM node:20-alpine WORKDIR /app ENV NODE_ENV=production COPY package*.json ./ COPY . . RUN npm ci --omit=dev EXPOSE 3000 USER node CMD ["node", "server.js"]
Build steps
- 1. Save as
Dockerfilein your project root - 2.
docker build -t myapp:latest . - 3.
docker run --rm -p 3000:3000 myapp:latest
What is a Dockerfile?
A Dockerfile is a plain-text recipe that tells the Docker build engine how to assemble a container image. Each instruction — FROM, COPY, RUN, ENV, CMD — runs in order and adds a new layer to the image. When you run docker build ., the engine reads the Dockerfile in the current directory and produces a runnable image. The same Dockerfile works with Podman, BuildKit, Buildah, and most container CI systems without modification.
Dockerfile Instructions Reference
Quick reference for every instruction this generator produces.
| Instruction | Purpose |
|---|---|
| FROM | Base image the build starts from. Must be the first instruction (after optional ARG). |
| WORKDIR | Set the working directory for subsequent RUN, COPY, CMD, ENTRYPOINT. |
| COPY | Copy files from the build context into the image. |
| ADD | Like COPY but also handles remote URLs and auto-extracts tar archives. Prefer COPY. |
| RUN | Execute a command at build time. Each RUN creates a new layer. |
| ENV | Set an environment variable available at build and runtime. |
| ARG | Build-time variable. Available only during build, not at runtime. |
| EXPOSE | Document which port the container listens on. Does not publish it. |
| USER | Set the user (and optionally group) for subsequent instructions and the running container. |
| CMD | Default command/arguments. Overridable at `docker run`. |
| ENTRYPOINT | Fixed prefix of the container command. CMD becomes its arguments. |
| HEALTHCHECK | Probe the container periodically; report healthy/unhealthy. |
| VOLUME | Declare a mount point with anonymous-volume semantics. |
| LABEL | Attach metadata key=value pairs to the image. |
Dockerfile Best Practices
Pin your base image
Use a specific tag like node:20-alpine, not :latest. Better still, pin by digest (image@sha256:...) for fully reproducible builds.
Order layers from least to most volatile
COPY package.json && install dependencies before COPY of source. Source changes won't bust the dependency-install cache.
Combine RUN instructions
Each RUN creates a layer. Chain related commands with && \ and clean caches in the same layer (e.g. rm -rf /var/lib/apt/lists/*).
Use multi-stage builds
Compile in a fat builder image, COPY --from=builder into a slim runtime. Drops compilers, dev deps, and toolchains from the shipped image.
Run as a non-root USER
Most base images include a non-root account (e.g. node). Set USER before CMD so the process drops privileges.
Prefer COPY over ADD
COPY is predictable. ADD also fetches URLs and auto-extracts tarballs — usually surprising. Use ADD only when you need those features.
Use exec-form CMD/ENTRYPOINT
CMD ["node", "server.js"] receives signals directly. The shell form runs under /bin/sh -c and swallows SIGTERM on shutdown.
Add a .dockerignore
Exclude node_modules, .git, build artifacts, and secrets from the build context to make builds faster and smaller.
Dockerfile Examples by Stack
Common base-image picks for popular runtimes. Use them as the starting point for the FROM field above.
| Stack | Base image | Typical CMD |
|---|---|---|
| Node.js | node:20-alpine | node server.js |
| Next.js | node:20-alpine (build) → node:20-alpine (run) | node .next/standalone/server.js |
| Python | python:3.12-slim | python app.py |
| FastAPI | python:3.12-slim | uvicorn main:app --host 0.0.0.0 --port 8000 |
| Java / Spring Boot | eclipse-temurin:21-jre | java -jar app.jar |
| Go | golang:1.23-alpine (build) → scratch (run) | /app |
| Static site (Nginx) | nginx:alpine | nginx -g 'daemon off;' |
Frequently Asked Questions
What is a Dockerfile?
What is the difference between CMD and ENTRYPOINT in a Dockerfile?
What is the difference between ARG and ENV in a Dockerfile?
What is the difference between COPY and ADD in a Dockerfile?
Why use a multi-stage Dockerfile build?
Related Tools
Docker Compose Generator
Build docker-compose.yml visually. Add services, volumes, networks, env vars — with live YAML and lint warnings.
Firewall Rule Generator
Cross-platform firewall rule builder (UFW, iptables, nftables, Windows, AWS, GCP). Also explains existing rules.
iptables to nftables
Convert iptables rules to nftables. Translates chains, NAT, conntrack, and common matchers.
Nginx Config Generator
Generate nginx.conf from form inputs. Reverse proxy, SSL, static files, load balancer, and basic auth — all common modes.
Nginx to Caddy Converter
Convert nginx server blocks to Caddyfile syntax. Maps reverse_proxy, TLS, redirects, and headers.
Need to manage SSH connections?
SSH Workbench lets you connect, browse files, and manage servers visually.
Try SSH Workbench Free