将命令从 docker 容器公开到主容器 shell
Exposing commands from docker container to main shell
我想知道我是否可以以某种方式在容器外部公开一些它的内部命令。
例如我们有 this 图片。
我们运行容器就在那。目的是有可能在我们的 shell.
外部使用该容器内部的命令,如 npm
、node
等
更深入 我想准备开发环境,您甚至不需要在您的 PC 上安装 node
或 npm
。只需简单地拉动码头工人,运行 它并使用必要的命令。
这可能吗?
是的,这是可能的。诀窍是将您的卷安装在容器内。例如docker run -v ${PWD}:/src mkenney/npm:latest npm
完整示例:
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
但是每次打字太长了。您可以创建一个别名。
alias mynpm='docker run --rm -it -v ${PWD}:/src mkenney/npm:latest npm'
mynpm list
# You will see the list of your package.json
我想知道我是否可以以某种方式在容器外部公开一些它的内部命令。
例如我们有 this 图片。 我们运行容器就在那。目的是有可能在我们的 shell.
外部使用该容器内部的命令,如npm
、node
等
更深入 我想准备开发环境,您甚至不需要在您的 PC 上安装 node
或 npm
。只需简单地拉动码头工人,运行 它并使用必要的命令。
这可能吗?
是的,这是可能的。诀窍是将您的卷安装在容器内。例如docker run -v ${PWD}:/src mkenney/npm:latest npm
完整示例:
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
但是每次打字太长了。您可以创建一个别名。
alias mynpm='docker run --rm -it -v ${PWD}:/src mkenney/npm:latest npm'
mynpm list
# You will see the list of your package.json