如何在 Dockerfile 中为全局包设置自定义 npm 目录?

问题描述 投票:0回答:1

我刚刚阅读了有关 全局 npm 依赖项的最佳实践,并尝试在我的 Dockerfile 中使用此方法:

FROM node:carbon
...
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH="/home/node/.npm-global:${PATH}"
...
RUN npm install -g nodemon
...
CMD ["nodemon", "server.js"]
USER node

但是当我尝试启动容器时,我得到:

ERROR: for my_project_node_1  Cannot start service my_project_node:
OCI runtime create failed: container_linux.go:296: 
starting container process caused "exec: \"nodemon\": 
executable file not found in $PATH": unknown

ERROR: for my_project_node  Cannot start service my_project_node: 
OCI runtime create failed: container_linux.go:296: 
starting container process caused "exec: \"nodemon\": 
executable file not found in $PATH": unknown

我只是不明白我做错了什么..

如何在我从这里获得的 Dockerfile 中设置 PATH 环境变量https://stackoverflow.com/a/38742545/202550

node.js docker npm dockerfile
1个回答
0
投票

您可能需要添加 .npm/bin 目录的路径,而不是 .npm 本身。

ENV PATH="/home/node/.npm-global/bin:${PATH}"
© www.soinside.com 2019 - 2024. All rights reserved.