Generate a Dockerfile Online
Create optimized Dockerfiles for your application stack. Supports multi-stage builds, common base images, and best practices for Node.js, Python, Go, Ruby, and Java.
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 org.opencontainers.image.authors="team@example.com" \
org.opencontainers.image.version="1.0.0" \
org.opencontainers.image.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 --omit=dev
COPY --from=builder /app/dist ./dist
RUN apk add --no-cache curl
# Create non-root user for security
RUN addgroup -S appusergroup && adduser -S appuser -G appusergroup
USER appuser
EXPOSE 3000
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.
Quick Start
- 1Select your language and framework
- 2Configure build and runtime options
- 3Preview the generated Dockerfile
- 4Copy or download the Dockerfile
More Generate Tools
All generators →Generate a .gitignore File Online
Generate .gitignore files for any language or framework. Free online gitignore generator with templates for Node.js, Python, Java, and more.
Generate GitHub Actions Workflows Online
Generate GitHub Actions CI/CD workflow YAML files. Free online GitHub Actions generator with templates for testing, building, and deploying.
Generate a GitHub README Profile Online
Generate a stunning GitHub profile README.md with stats, skills, and social links. Free online GitHub README generator.
Generate Hreflang Tags for Multilingual SEO
Generate hreflang link tags for multilingual and multi-regional websites. Free online hreflang tag generator.
Generate JSON-LD Structured Data Online
Generate JSON-LD structured data for rich snippets in Google search. Free online JSON-LD generator for Article, Product, FAQ, and more.
Generate JSON Schema from Sample Data Online
Paste JSON data and generate a JSON Schema definition automatically. Free online JSON Schema generator.
Looking for FAQs and advanced options? Visit the full Dockerfile Generator page →