Dockerfile Generator
Generate production-ready Dockerfiles with multi-stage builds, security best practices, and .dockerignore files
Configure: Node.js
Best Practices: Node.js
- Copy package.json and lockfile before source code so the dependency layer is cached separately
- Use --frozen-lockfile / npm ci to ensure reproducible builds
- Multi-stage builds keep the final image small by discarding build-time dependencies
- Always run as a non-root user in production containers
- Pin your Node.js major version (e.g. node:22-alpine) for stability
# Pin to specific version in production, e.g., node:22.11-alpine
# Stage 1: Install dependencies
FROM node:22-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
# Stage 2: Build (if applicable)
FROM node:22-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
# Stage 3: Production image
FROM node:22-alpine AS runner
LABEL maintainer="team@example.com" \
version="1.0.0" \
description="Production image"
WORKDIR /app
ENV NODE_ENV=production
# Copy only production dependencies and built output
COPY package.json package-lock.json ./
RUN npm ci --only=production
COPY --from=builder /app/dist ./dist
# Create non-root user for security
RUN addgroup -S appusergroup && adduser -S appuser -G appusergroup
USER appuser
EXPOSE 3000
RUN apk add --no-cache curl
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3000/ || exit 1
# Use ENTRYPOINT for proper signal handling (PID 1)
ENTRYPOINT ["node"]
CMD ["dist/index.js"]
How to Use
- Select your stack and configure the options to match your project.
- Download both the
Dockerfileand.dockerignorefiles, or copy the content. - Place both files in the root of your project directory.
- Build your image:
docker build -t my-app . - Run your container:
docker run -p 3000:3000 my-app
Review before deploying. These Dockerfiles are a solid starting point but may need adjustments for your specific project structure, environment variables, and production requirements.
Was this tool helpful?
Related Tools
.gitignore Generator
Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS
Git Commit Message Generator
Free online git commit message generator - generate conventional commit messages with type, scope, and description
package.json Generator
Generate package.json files with a form-based builder - 8 project presets, all fields supported
Changelog Generator
Generate changelogs in Keep a Changelog format - version entries, semver, and diff links
XML Sitemap Generator
Free online XML sitemap generator - generate XML sitemaps from a list of URLs
GitHub Actions Generator
Free online github actions generator - generate CI/CD workflow YAML files from templates