在安装全局模块后的Docker中找不到该模块

在安装全局模块后的Docker中找不到该模块

本文介绍了在安装全局模块后的Docker中找不到该模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的Dockerfile来全局安装一些节点工具.

I created a simple Dockerfile to install some node tools globally.

FROM node:10.9.0
RUN npm -g config set user root
RUN npm -g install --unsafe-perm merge-yaml
RUN mkdir -p /workDirectory
WORKDIR /workDirectory

构建图像,我希望可以在任何路径上(全球)使用merge-yaml

Building the image i expect that merge-yaml will be availabe on any path (globally)

docker build -t  thisisme/devtools .

但是使用exec找不到命令

But using as exec the command is not found

docker run --rm -it -v ${PWD}:/workDirectory thisisme/devtools merge-yaml

docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"merge-yaml\": executable file not found in $PATH".

如果我进入容器并确认模块未全局添加:

If I enter into the container and verify the module is not added globally:

docker run --rm -it  thisisme/devtools /bin/bash
root@e77027bb2f57:/workDirectory# merge-yaml
bash: merge-yaml: command not found

我确定我做错了,因为在交互模式下全局安装并且无法正常工作(如我预期的那样)

I am sure that i am doing wrong because, in interactive mode install globally and not works (as I expected)

root@e77027bb2f57:/workDirectory# npm install -g merge-yaml
+ [email protected]
updated 1 package in 0.584s
root@e77027bb2f57:/workDirectory# merge-yaml
bash: merge-yaml: command not found
root@e77027bb2f57:/workDirectory#

预先感谢

推荐答案

如果要使用命令行,则应改为安装 merge-yaml-cli .

If you want to use the command line, then you should install merge-yaml-cli instead.

Dockerfile:

Dockerfile :

FROM node:10.9.0
RUN npm -g config set user root
RUN npm -g install --unsafe-perm merge-yaml-cli
RUN mkdir -p /workDirectory
WORKDIR /workDirectory

构建图像后,可以使用merge-yaml:

After building the image, merge-yaml will then be available :

user@term:~/work $ docker run --rm -it quentin/test merge-yaml
Usage: /usr/local/bin/merge-yaml <options>

Options:
  -i, --inputs  Input files specified as glob file patterns   [array] [required]
  -o, --output  Output file                                  [string] [required]

Examples:
  /usr/local/bin/merge-yaml -i one.yml two/*.yml -o out.yml

Missing required arguments: i, o

这篇关于在安装全局模块后的Docker中找不到该模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 09:56