A Windows/Linux script that runs npm commands inside Docker containers.
- Runs ALL npm commands in Docker, no local Node/npm required.
- Automatically detects
.nvmrcand selects matching Node major version (e.g.,node:18-alpine). - Supports hoisted / shared
node_modulesin monorepos. - Automatically mounts nearest
node_modulesto/app/node_modules. - Supports blocklisted files through
.npm-docker-ignore. - Supports port forwarding using
.npm-docker-ports. - Pure Docker — Node installations NOT required.
- Place
npm-docker.cmdin a directory included in yourPATH(e.g.,C:\npm-docker\). - Optionally rename it to
npm.cmdto fully replace the hostnpm. - Requires Docker installed and running.
- Copy the script to
/usr/local/bin/:sudo cp npm-docker.sh /usr/local/bin/npm-docker
- Make it executable:
sudo chmod +x /usr/local/bin/npm-docker
- Optionally create a symlink named
npmto fully replace the hostnpm:sudo ln -sf /usr/local/bin/npm-docker /usr/local/bin/npm
If your node_modules is located outside the project folder,
the script automatically searches parent directories and mounts the first one it finds into:
/app/node_modules
No configuration needed — automatic detection.
If .nvmrc exists, the script reads the major version only:
.nvmrc:
18.16.1
Script will automatically use:
node:18-alpine
No more need to manage node versions.
Create a .npm-docker-ports file in your project root:
3000
4200:4200
8080:80
Do not expose your secrets to the internet.
Create .npm-docker-ignore to prevent mounting certain paths:
.env
dist
.secret-config
The script masks files/dirs using empty placeholders.
| Benefit | Description |
|---|---|
| Safety | npm runs sandboxed in Docker |
| Consistency | Same Node version, same OS, same environment across all machines |
| Zero Host Pollution | No local Node, npm, or dependencies required |
npm-docker respects the ignore-scripts=true setting in your .npmrc file (local or global).
This is recommended for security — it prevents automatic execution of npm lifecycle scripts (preinstall, postinstall, etc.) which can be a security risk.
To enable, add to your .npmrc file:
ignore-scripts=true
Or set it globally:
npm config set ignore-scripts true- Large npm dependency trees can cause "file count" or inode errors in WSL2 when the project resides on a mounted Windows path (e.g. /mnt/c/...).
- Fix: Move the project to a native Linux path such as /home/user/ inside WSL2.
MIT License
Created by Eldar Gerfanov.
Use at your own risk.
This script can fully replace npm on Windows — safer, cleaner, and portable.
rename npm-docker.cmd to npm.cmd
put it first in PATH
enjoy isolated npm everywhere
Pull requests welcome!
