npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

dockerfile-slim

v1.0.0

Published

Analyze and optimize Dockerfiles - reduce image size by up to 80%

Downloads

107

Readme

dockerfile-slim

Analyze and optimize Dockerfiles - reduce image size by up to 80%

npm version License: MIT

Problem

Your Docker image is 2GB. Deploys take forever. Registry storage costs money.

Solution

dockerfile-slim analyzes your Dockerfile and provides actionable optimization suggestions with estimated size and cost savings.

Features

  • Instant analysis - No Docker build required
  • Base image alternatives - Suggests smaller base images (e.g., node → node:alpine)
  • Multi-stage build detection - Identifies missing multi-stage opportunities
  • Layer optimization - Finds inefficient layer patterns
  • Cache optimization - Detects poor layer caching strategies
  • Cost estimation - Shows monthly registry cost savings
  • Auto-fix - Generates optimized Dockerfiles
  • .dockerignore generation - Prevents bloat from unnecessary files

Installation

# Run directly with npx (recommended)
npx dockerfile-slim

# Or install globally
npm install -g dockerfile-slim

# Or as dev dependency
npm install --save-dev dockerfile-slim

Usage

Basic Analysis

# Analyze Dockerfile in current directory
npx dockerfile-slim

# Analyze specific Dockerfile
npx dockerfile-slim ./path/to/Dockerfile

# Output as JSON (for CI/CD)
npx dockerfile-slim --json

Generate Optimized Dockerfile

# Generate and display optimized Dockerfile
npx dockerfile-slim --fix

# Save to file
npx dockerfile-slim --fix --output Dockerfile.optimized

# Also generate .dockerignore
npx dockerfile-slim --fix --dockerignore

Example Output

📦 Dockerfile Analysis
──────────────────────────────────────────────────

File:             ./Dockerfile
Base Image:       node:18
Estimated Size:   1.2 GB
Layer Count:      8
Efficiency Score: 35/100

💡 Found 5 optimization opportunities:

🔴 Critical

🔴 Smaller base image available
   Switch from node:18 to node:18-alpine
   → Potential savings: 965 MB
   → Cost savings: ~$5.30/month

🔴 Missing multi-stage build (Node.js)
   Node.js projects should use multi-stage builds
   → Potential savings: 800 MB
   → Cost savings: ~$4.40/month

🟠 High Priority

🟠 apt-get without cleanup
   apt-get install without cleaning cache adds ~50-200MB
   Line 5
   → Potential savings: 100 MB
   → Add cleanup in same RUN: && rm -rf /var/lib/apt/lists/*

🟠 Missing .dockerignore
   Without .dockerignore, unnecessary files may be included
   → Potential savings: 200 MB

🟡 Medium Priority

🟡 npm cache not cleaned
   npm cache can add 50-100MB
   → Potential savings: 50 MB
   → Add npm cache clean --force after install

──────────────────────────────────────────────────

Summary                      Value
───────────────────────────────────────
Total potential savings      2.0 GB
Estimated cost savings       $11.20/month
Potential size reduction     80%

💡 Run with --fix to generate an optimized Dockerfile

Generated Dockerfile Example

Running npx dockerfile-slim --fix generates:

# syntax=docker/dockerfile:1

# ---- Build Stage ----
FROM node:20-slim AS builder

WORKDIR /app

# Copy package files first for better layer caching
COPY package.json package-lock.json* ./

# Install ALL dependencies (including devDependencies for build)
RUN npm ci

# Copy source code
COPY . .

# Build the application
RUN npm run build

# ---- Production Stage ----
FROM node:20-slim AS production

# Create non-root user for security
RUN groupadd --gid 1001 nodejs && \
    useradd --uid 1001 --gid nodejs --shell /bin/bash --create-home nodejs

WORKDIR /app

# Copy package files
COPY package.json package-lock.json* ./

# Install production dependencies only
RUN npm ci --omit=dev && \
    npm cache clean --force

# Copy built application from builder stage
COPY --from=builder /app/dist ./dist

# Set ownership to non-root user
RUN chown -R nodejs:nodejs /app

USER nodejs

EXPOSE 3000

CMD ["node", "dist/index.js"]

Comparison with Other Tools

| Tool | Analysis | Auto-Fix | Cost Est. | npm Native | Maintained | |------|----------|----------|-----------|------------|------------| | dockerfile-slim | ✅ | ✅ | ✅ | ✅ | ✅ | | Hadolint | ✅ | ❌ | ❌ | ❌ (Haskell) | ✅ | | Dive | ✅ | ❌ | ❌ | ❌ (Go) | ✅ | | SlimToolkit | ✅ | ✅* | ❌ | ❌ (Go) | ✅ | | dockerfile_lint | ✅ | ❌ | ❌ | ✅ | ❌ (2019) | | Dockershrink | ✅ | ✅ | ❌ | ✅ | ⚠️ (Beta) |

*SlimToolkit optimization can break apps with dynamic dependencies

Why dockerfile-slim?

  • npm native - No binary installation, just npx
  • Instant analysis - No Docker build required
  • Actionable suggestions - Not just problems, but specific fixes
  • Cost estimation - Justify optimization work to stakeholders
  • Actively maintained - Unlike abandoned npm alternatives

CLI Options

Usage: dockerfile-slim [path] [options]

Arguments:
  path                    Path to Dockerfile or directory (default: ".")

Options:
  --json                  Output results as JSON
  --fix                   Generate an optimized Dockerfile
  -o, --output <file>     Output file for generated Dockerfile
  --dockerignore          Generate a .dockerignore file
  -V, --version           Output version number
  -h, --help              Display help

CI/CD Integration

# GitHub Actions example
- name: Analyze Dockerfile
  run: npx dockerfile-slim --json > dockerfile-analysis.json

- name: Check for critical issues
  run: |
    CRITICAL=$(cat dockerfile-analysis.json | jq '.optimizations | map(select(.severity == "critical")) | length')
    if [ "$CRITICAL" -gt 0 ]; then
      echo "Found $CRITICAL critical Dockerfile issues"
      exit 1
    fi

Optimization Database

Includes rules for:

Base Images:

  • Ubuntu → Debian Slim → Alpine
  • Node.js → node:slim → node:alpine → distroless
  • Python → python:slim → python:alpine → distroless
  • Go → golang:alpine → scratch/distroless
  • Java → eclipse-temurin:jre → distroless

Common Issues:

  • Missing multi-stage builds
  • apt-get without cleanup
  • npm/pip cache not cleaned
  • Multiple RUN commands (layer bloat)
  • Poor layer caching order
  • Running as root
  • Using :latest tag

Requirements

  • Node.js 18.0.0 or higher

Contributing

Contributions welcome! Especially:

  • Adding more optimization patterns
  • Improving size estimates
  • Adding more base image alternatives
  • Better language-specific Dockerfile generation

Related Projects

Support

This project is maintained in my free time. If it helped reduce your Docker image size or saved you debugging time, I'd really appreciate your support:

Thank you to everyone who has contributed, shared feedback, or helped spread the word!

License

MIT


Made with ❤️ for smaller Docker images