Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PATH wrong (node not found) when running container-image with non-interactive shell like in Gitlab CICD-Jobs #3531

Open
zenhighzer opened this issue Feb 20, 2025 · 4 comments

Comments

@zenhighzer
Copy link

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

@ljharb
Copy link
Member

ljharb commented Feb 20, 2025

If you omit the yarn parts, a PR to make that change would be great! that way it can get proper review.

@zenhighzer
Copy link
Author

zenhighzer commented Feb 21, 2025

Hi,

I think i dont have permissions to create PR. I am not very familiar with github tbh.
I updated the README / added a further docker-section.

Maybe you could have a look and create a PR?

README.md

@ljharb
Copy link
Member

ljharb commented Feb 21, 2025

Everyone has permissions to make a PR :-) I’ll take a look, i can probably apply your patch.

@zenhighzer
Copy link
Author

damn, next time i will try to create a PR :-)
Thank you very much! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants