Detection
migetpacks detects Node.js when any of these files are present in your project root:package.jsonpackage-lock.jsonyarn.lockpnpm-lock.yaml
Package Manager Detection
The package manager is detected from lockfiles first, then from thepackageManager field in package.json:
Version Detection
Node.js version is resolved in this order:
Version constraints are normalized for Docker compatibility:
20.xbecomes20>=18becomes18^20.0.0becomes20.020.x || 22.x || 24.xbecomes24(highest major)
Build Process
migetpacks generates a multi-stage Dockerfile optimized for layer caching:Package Manager Commands
Build Script
Ifpackage.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 meansnpm ci is only re-run when package.json or package-lock.json changes.
BuildKit Cache Mounts
WhenBUILD_CACHE_DIR is configured, BuildKit cache mounts are used for package manager caches:
Registry Cache
UseCACHE_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 variablesNEXT_PUBLIC_*- Next.js public environment variables