Docker:未找到 npm

新手上路,请多包涵

我有以下 Dockerfile:

 FROM ubuntu
USER root
RUN apt-get update && apt-get install curl -y
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get update && apt-get upgrade -y && apt-get install nodejs -y
RUN mkdir /opt/public
RUN mkdir /opt/bin
ADD public /opt/public
ADD bin /opt/bin
RUN ls -lah /opt/bin
RUN ls -lah /opt/public
ADD run.sh /bin/run.sh
RUN chmod +x /bin/run.sh
RUN cd /opt/bin && npm install
CMD ["/bin/run.sh"]

当我构建容器时,我得到了这个错误:

/bin/sh: 1: npm: 未找到

问题是什么?请你帮助我好吗?

原文由 Sohrab 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.4k
2 个回答

尝试在构建映像时单独安装 npm

 RUN apt-get update && apt-get upgrade -y && \
    apt-get install -y nodejs \
    npm                       # note this one

原文由 Yury Fedorov 发布,翻译遵循 CC BY-SA 4.0 许可协议

Node 也包 npm ,所以不需要像 Yury 提到的那样安装 npm 。这样做通常是个坏主意,因为您无法控制 nodejsnpm 版本

对我来说,答案很简单。我有以下代码:

 # install nodejs
RUN curl --silent --location https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install -y \
  nodejs
RUN echo "Node: " && node -v
RUN echo "NPM: " && npm -v

但我必须安装 curl,所以它失败了。所以在此之前,你需要安装curl:

 RUN apt-get update && apt-get install -y curl

原文由 bersling 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题