Description
Hi,
we followed your guide with a slightly modification:
https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-in-docker:
FROM ubuntu:latest
ARG NODE_VERSION=20
RUN apt update && apt install -y curl
# Use bash for the shell
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# Create a script file sourced by both interactive and non-interactive bash shells
ENV BASH_ENV=/root/.bash_env
RUN touch "${BASH_ENV}"
RUN echo '. "${BASH_ENV}"' >> ~/.bashrc
# Download and install nvm
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | PROFILE="${BASH_ENV}" bash
RUN echo node > .nvmrc
RUN nvm install $NODE_VERSION && npm install --global yarn
But running the container like 'docker run --rm -it testnvm yarn -v' throws some error:
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: exec: "yarn": executable file not found in $PATH: unknown
If we start Container interactively the PATH is OK;
docker run --rm -it testnvm:latest bash
root@7a71be1a2bec:/# yarn -v
1.22.22
root@7a71be1a2bec:/#
So we asked gpt for help. after several tries this Dockerfile seems to be working fine with interactive and non-interactive containers:
FROM ubuntu
ARG NODE_VERSION=20
# install curl
RUN apt update && apt install curl -y
# install nvm
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
# set env
ENV NVM_DIR=/root/.nvm
# install nodejs and yarn
RUN bash -c "source $NVM_DIR/nvm.sh && \
nvm install $NODE_VERSION && \
nvm alias default $NODE_VERSION && \
nvm use default && \
npm install -g yarn"
# test node and yarn installation
RUN bash -c "source $NVM_DIR/nvm.sh && node -v && yarn -v"
# set ENTRYPOINT for reloading nvm, node-env, etc. everytime
ENTRYPOINT ["bash", "-c", "source $NVM_DIR/nvm.sh && exec \"$@\"", "--"]
# set cmd to bash
CMD ["/bin/bash"]
So I wonder if you want to update your example for a more robust nodejs-container.
Best Regards