Detection

migetpacks detects Node.js when any of these files are present in your project root:
  • package.json
  • package-lock.json
  • yarn.lock
  • pnpm-lock.yaml

Package Manager Detection

The package manager is detected from lockfiles first, then from the packageManager field in package.json:
If multiple lockfiles are detected (e.g., both yarn.lock and package-lock.json), migetpacks will warn you and use the highest-priority lockfile. Remove unused lockfiles to avoid confusion.

Version Detection

Node.js version is resolved in this order: Version constraints are normalized for Docker compatibility:
  • 20.x becomes 20
  • >=18 becomes 18
  • ^20.0.0 becomes 20.0
  • 20.x || 22.x || 24.x becomes 24 (highest major)

Build Process

migetpacks generates a multi-stage Dockerfile optimized for layer caching:

Package Manager Commands

Build Script

If package.json contains a "build" script, it is automatically executed after dependency installation. You can override this with the BUILD_COMMAND environment variable.

Runtime Cleanup

The following directories are removed from the final image:
  • .git/, .github/
  • test/, tests/, spec/, __tests__/
  • coverage/, .nyc_output/, .cache/

Run Command

The default run command is determined in this order:

Caching

Docker Layer Caching

Dependencies are installed in a separate layer before source code is copied. This means npm ci is only re-run when package.json or package-lock.json changes.

BuildKit Cache Mounts

When BUILD_CACHE_DIR is configured, BuildKit cache mounts are used for package manager caches:

Registry Cache

Use CACHE_IMAGE to push/pull BuildKit inline cache layers to a registry for cross-build caching.

DHI Support

Node.js is fully supported with Docker Hardened Images.
The -dev variant includes a shell and package manager for building. The runtime image is distroless with no shell, providing a minimal attack surface.
DHI runtime images run as the node user (non-root). Commands must use exec format since there is no /bin/sh available.

Example

With Custom Options

Environment Variables

Any environment variable not recognized by migetpacks is automatically injected into the generated Dockerfile. Common Node.js variables:
  • NODE_OPTIONS - Node.js runtime options (e.g., --max-old-space-size=4096)
  • VITE_* - Vite build-time variables
  • NEXT_PUBLIC_* - Next.js public environment variables