This docker utility container will help us execute npm commands without installing node in our machine. I've used node 20.10-alpine version in this project.
docker run -it --rm --name node-util node:20.10-alpinedocker run -it -d --rm --name node-util node:20.10-alpine- Executing npm command (say
npm init)
docker exec -it node-util npm initThe docker exec command helps us to execute(run) a new command inside the running container.
- Build the image
docker build . -t actionanand/node-util- You can run any command begining with
npm(leavenpmand add remaining at the end of following command)
docker run -it --rm --name node-util -v "D:\AR_extra\rnd\docker\node-util:/app" actionanand/node-utilFor wsl2, mac and linux
docker run -it --rm --name node-util -v $(pwd):/app actionanand/node-utilTo run npm init command
docker run -it --rm --name node-util -v $(pwd):/app actionanand/node-util initTo run npm install express
docker run -it --rm --name node-util -v $(pwd):/app actionanand/node-util install expressdocker-compose runis used to run single service from multiple services present indidedocker-compose.yaml
Usage
docker-compose run --rm <service_name>Consider npm-util is the registered service name in docker-compose.yaml and If you want to execute npm init, the following will be the command to be executed!
docker-compose run --rm npm-util initSo if npm is the registered service name,
docker-compose run --rm npm init



