gpt4 book ai didi

docker - 在安装全局模块后在 Docker 中找不到模块

转载 作者:行者123 更新时间:2023-12-02 20:35:05 27 4
gpt4 key购买 nike

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

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 将在任何路径上可用(全局)
docker build -t  thisisme/devtools .
但是使用 as exec 找不到命令
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".
如果我进入容器并验证模块未全局添加:
docker run --rm -it  thisisme/devtools /bin/bash
root@e77027bb2f57:/workDirectory# merge-yaml
bash: merge-yaml: command not found
我确定我做错了,因为在交互模式下全局安装并且不起作用(如我所料)
root@e77027bb2f57:/workDirectory# npm install -g merge-yaml
+ merge-yaml@1.1.0
updated 1 package in 0.584s
root@e77027bb2f57:/workDirectory# merge-yaml
bash: merge-yaml: command not found
root@e77027bb2f57:/workDirectory#
提前致谢

最佳答案

如果你想使用命令行,那么你应该安装merge-yaml-cli反而。
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 将可用:
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 - 在安装全局模块后在 Docker 中找不到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64133397/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com