node.js - Set path to npm in dockerfile - Stack Overflow

I'm writing a dockerfile to run open5Gs. It requires nodenpm. My dockerfile looks like this:EN

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?

Share Improve this question edited Mar 25 at 3:40 Phil 165k25 gold badges262 silver badges267 bronze badges asked Mar 25 at 2:05 user101289user101289 10.5k18 gold badges94 silver badges163 bronze badges 2
  • 2 Running nvm in a container seems a very odd choice. Why not simply use an appropriate base image like node:22.14.0? – Phil Commented Mar 25 at 2:07
  • 1 Does How to install nvm in docker? help you? As @phil indicates in their answer, using the Docker Hub node 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 removing npm from the end of the ENV PATH line). – David Maze Commented Mar 25 at 10:10
Add a comment  | 

1 Answer 1

Reset to default 1

A 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744220272a4563748.html

相关推荐

  • node.js - Set path to npm in dockerfile - Stack Overflow

    I'm writing a dockerfile to run open5Gs. It requires nodenpm. My dockerfile looks like this:EN

    8天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信