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.com/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.org/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?
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.org/repositories/home:/acetcom:/open5gs:/latest/Debian_11/Release.key | apt-key add - && \
echo 'deb http://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/Debian_11/ ./' > /etc/apt/sources.list.d/open5gs.list && \
apt-get update && apt-get install -y open5gs