Docker Utility Containers & Executing Commands - (Section 5)
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.
How to run node in interactive mode as shell in our machine
docker run -it --rm --name node-util node:20.10-alpine

How to run node in interactive mode without any Dockerfile in terminal to use npm commands
docker run -it -d --rm --name node-util node:20.10-alpine
- Executing npm command (say
npm init)
docker exec -it node-util npm init
The docker exec command helps us to execute(run) a new command inside the running container.

Set-up using Dockerfile
- 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-util
For wsl2, mac and linux
docker run -it --rm --name node-util -v $(pwd):/app actionanand/node-util
To run npm init command
docker run -it --rm --name node-util -v $(pwd):/app actionanand/node-util init
To run npm install express
docker run -it --rm --name node-util -v $(pwd):/app actionanand/node-util install express

Set-up using docker-compose
docker-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 init
So if npm is the registered service name,
docker-compose run --rm npm init

