Node Docker Image Slimming
Techniques Developer Guide

Techniques

    • Overview
    • Baseline
  • Techniques
    • .dockerignore
    • npm ci
    • clean-modules
    • Smaller Base Image
    • Multi-Stage Build
    • Separate Serving Image
    • Harden the Image
    • Compress Node Binary
    • Bundle With External Packages
    • Bundle Without External Packages
    • Result
    • Recommendations
    • Running the Example
Techniques
  • Developer Guide
  • Techniques
  • Techniques
  • Overview

Techniques

Starting from a baseline (1740 MB) the result (105 MB) will be 93.97% smaller.

The following techniques will be shown:

  1. a .dockerignore file

  2. using npm ci

  3. a cleaned node_modules directory

  4. a smaller base image

  5. a multi-stage build

  6. a separate serving image

  7. a hardened image

  8. a UPX-compressed Node binary

  9. bundled JavaScript with external packages

  10. bundled JavaScript without external packages

Baseline

© 2025 Sebastian Davids