Patryk Janik
Patryk Janik

Reputation: 2623

Exposing commands from docker container to main shell

I was wondering if can I somehow expose outside of the container some its internal command.

Like for example we have this image. We run container on that. And the aim is to have the possibility of using commands which are inside of that container like npm, node etc. outside in our shell.

Going more deeply I want to prepare developer environment where you don't need to have installed even node or npm on your PC. Just simply pull dockers, run it and use necessary commands.

Is it even possible?

Upvotes: 3

Views: 236

Answers (1)

Rafael
Rafael

Reputation: 1885

Yes, it is possible. The trick is to mount your volume inside the container. For example docker run -v ${PWD}:/src mkenney/npm:latest npm

Full example:

docker pull mkenney/npm:latest
docker run --rm -it -v ${PWD}:/src mkenney/npm:latest npm init
# Complete your npm init questions
docker run --rm -it -v ${PWD}:/src mkenney/npm:latest npm install --save express
cat package.json
# You will see your package.json file

But it is too long to type every time. You could create an alias.

alias mynpm='docker run --rm -it -v ${PWD}:/src mkenney/npm:latest npm'
mynpm list
# You will see the list of your package.json

Upvotes: 2

Related Questions