admin管理员组文章数量:1400211
I'm writing a dockerfile to run open5Gs. It requires node / npm. My dockerfile looks like this:
ENV NVM_DIR=/root/.nvm
RUN curl -o- .40.2/install.sh | bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install 22 \
&& node --version \ # cli prints v22.14.0
&& npm --version \ # cli prints 10.9.2
&& which npm # cli prints /root/.nvm/versions/node/v22.14.0/bin/npm
# add the path we got from the line above to PATH var
ENV PATH="$PATH:/root/.nvm/versions/node/v22.14.0/bin/npm"
RUN echo $PATH # cli prints /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.nvm/versions/node/v22.14.0/bin/npm
RUN exec bash
RUN which npm # BLOWS UP, ERROR: process "/bin/sh -c which npm" did not complete successfully: exit code: 1
RUN add-apt-repository ppa:open5gs/latest \
&& apt-get update && apt-get install -y open5gs \
# install open5gs UI
&& curl -fsSL | bash -
# IF I try to run without setting path (like I'm attempting above), this part complains that it can't find npm
It seems that the path to npm
never gets set correctly, even when I explicitly add it to the path-- how can I make npm
accessible to the next script that needs it?
I'm writing a dockerfile to run open5Gs. It requires node / npm. My dockerfile looks like this:
ENV NVM_DIR=/root/.nvm
RUN curl -o- https://raw.githubusercontent/nvm-sh/nvm/v0.40.2/install.sh | bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install 22 \
&& node --version \ # cli prints v22.14.0
&& npm --version \ # cli prints 10.9.2
&& which npm # cli prints /root/.nvm/versions/node/v22.14.0/bin/npm
# add the path we got from the line above to PATH var
ENV PATH="$PATH:/root/.nvm/versions/node/v22.14.0/bin/npm"
RUN echo $PATH # cli prints /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.nvm/versions/node/v22.14.0/bin/npm
RUN exec bash
RUN which npm # BLOWS UP, ERROR: process "/bin/sh -c which npm" did not complete successfully: exit code: 1
RUN add-apt-repository ppa:open5gs/latest \
&& apt-get update && apt-get install -y open5gs \
# install open5gs UI
&& curl -fsSL https://open5gs./open5gs/assets/webui/install | bash -
# IF I try to run without setting path (like I'm attempting above), this part complains that it can't find npm
It seems that the path to npm
never gets set correctly, even when I explicitly add it to the path-- how can I make npm
accessible to the next script that needs it?
1 Answer
Reset to default 1A quick look into that install script shows the following...
if [ ! -x /usr/bin/npm ]; then print_status "First you need to install NPM packages." exit 1 fi
Your version of npm
is not installed in /usr/bin/npm
.
Using a version manager in a container just doesn't make much sense since there would be absolutely no reason to maintain multiple versions.
I would recommend simply using an appropriate base image. You can even make the specific version dynamic using a build arg.
ARG NODE_VERSION="22.14.0"
FROM --platform=linux/amd64 node:${NODE_VERSION}-bullseye # Debian 11
# Note: You need to install MongoDB before open5gs
RUN wget -qO - https://download.opensuse./repositories/home:/acetcom:/open5gs:/latest/Debian_11/Release.key | apt-key add - && \
echo 'deb http://download.opensuse./repositories/home:/acetcom:/open5gs:/latest/Debian_11/ ./' > /etc/apt/sources.list.d/open5gs.list && \
apt-get update && apt-get install -y open5gs
See here for the full installation instructions.
本文标签: nodejsSet path to npm in dockerfileStack Overflow
版权声明:本文标题:node.js - Set path to npm in dockerfile - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744220272a2595832.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
node:22.14.0
? – Phil Commented Mar 25 at 2:07node
image will often be easier, and using a version manager isn't usually a preferred path. Also double-check the syntax of the$PATH
variable: it is a list of directories, and you don't to include the name of the executable in it (try removingnpm
from the end of theENV PATH
line). – David Maze Commented Mar 25 at 10:10