Ok Thank you! I get it now. The problem I’m trying to solve is that I have built an image based on rockylinux:8 were I am installing node 18.17.1 using nvm (see dockerfile 1 below). I’m using this image to build nodejs native packages with napi to be served as a REST api with express. This is done in an interactive “shell”-mode (in a cicd pipeline). There I have access to the version of node that was installed.
But since it is a native application I also need a rockylinux:8 based image to run and serve those packages. So I want to build an executable image that starts the express server built on that same image (see dockerfile 2 below). When this image is run in executable mode, the container does not use the shell environment that I was in when building it. “npm -v” and “node -v” shows the old versions that comes with rocky8 (v10.24.0). In order to use node 18.17.1, I need to run “npm install” prefixed with with “/bin/bash -c -l” and use a CMD with “/root/.nvm/versions/node/v18.17.1/bin/node” instead of just “node”. When I run it interactively with -it I get into the shell environment and all works fine.
This is not a huge problem, but I’m want to learn if there is a way to run the image in an executable mode and get into the same shell environment that you do when you run it interactively.
dockerfile 1, used to produce an image /user/napi-build-rocky8:
FROM rockylinux:8
RUN dnf install epel-release -y
RUN dnf install cmake3 gcc gcc-c++ make -y;
RUN wget -qO- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash &&\
source ~/.bashrc &&\
nvm install 18.17.1 &&\
nvm use 18.17.1 &&\
npm install -g node-gyp node-addon-api
dockerfile 2 (based on the image built in dockerfile 1):
FROM /user/napi-build-rocky8
WORKDIR /app
COPY . .
RUN /bin/bash -c -l "npm install"
EXPOSE 8080
CMD [ "/root/.nvm/versions/node/v18.17.1/bin/node", "server.js" ]```