Back to Tools
Tool
Dockerfile Generator
Generate optimized, multi-stage Dockerfiles for your runtime. Pick a language, set the port, and copy.
# Dockerfile for Node.js FROM node:20-alpine WORKDIR /app # Copy package files first (layer caching) COPY package*.json ./ RUN npm ci --only=production # Copy source code COPY . . RUN npm run build EXPOSE 3000 CMD ["node", "dist/index.js"]
Dockerfile Best Practices
- Order layers by change frequency - package dependencies first (slowest to change), source code last. Maximizes build cache usage.
- Use multi-stage builds - compilers and build tools go in stage 1; only the runtime binary goes in production. Cuts image size by 5-10x.
- Don't run as root - create a non-root user with `adduser` and switch with `USER`. Security 101.
- Pin base image versions - `node:20-alpine` not `node:latest`. Reproducible builds save you from “works on my machine”.