1

I run a given Dockerfile in order to build image for my TeamCity Agent

FROM jetbrains/teamcity-agent:2022.10.1-linux-sudo

RUN curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
RUN sudo sh -c 'echo deb https://apt.kubernetes.io/ kubernetes-xenial main > /etc/apt/sources.list.d/kubernetes.list'

RUN curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -

# https://github.com/AdoptOpenJDK/openjdk-docker/blob/master/12/jdk/ubuntu/Dockerfile.hotspot.releases.full
RUN sudo apt-get update && \
    sudo apt-get install -y ffmpeg gnupg2 git sudo kubectl \
    binfmt-support qemu-user-static mc jq
    
#RUN wget -O - https://apt.kitware.com/keys/kitware-archive-la3est.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null
#RUN sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main' && \
#    sudo apt-get update && \
RUN sudo apt install -y cmake build-essential wget

RUN sudo curl -L https://nodejs.org/dist/v14.17.3/node-v14.17.3-linux-x64.tar.gz --output node-v14.17.3-linux-x64.tar.gz

RUN sudo tar -xvf node-v14.17.3-linux-x64.tar.gz 

RUN echo 'export PATH="$HOME/node-v14.17.3-linux-x64/bin:$PATH"' >> ~/.bashrc

RUN echo "The version of Node.js is $(node -v)"

All the code was right, but then I decided to add node.js installation to the Dockerfile. that begins from this line:

RUN sudo curl -L https://nodejs.org/dist/v14.17.3/node-v14.17.3-linux-x64.tar.gz --output node-v14.17.3-linux-x64.tar.gz

However, the problem right now is that I have the following error, during execution of the last line of the Dockerfile:

RUN echo "The version of Node.js is $(node -v)"

Output for this line is:

Step 10/22 : RUN echo "The version of Node.js is $(node -v)"
21:07:41    ---> Running in 863b0e75e45a
21:07:42   /bin/sh: 1: node: not found
  • Check this out: https://stackoverflow.com/questions/36399848/install-node-in-dockerfile – tehCheat Dec 28 '22 at 23:29
  • Does this answer your question? [Install node in Dockerfile?](https://stackoverflow.com/questions/36399848/install-node-in-dockerfile) – tehCheat Dec 28 '22 at 23:30
  • Are you actually unpacking the tar file anywhere? (Also note, you don't need `sudo` here since you're probably already `USER root`, and I'd avoid installing it in an image.) – David Maze Dec 29 '22 at 11:50

1 Answers1

-1

You need to make the 2 following changed in your Dockerfile for your node installation to be included in your $PATH env var -

  1. Remove the $HOME variable from the path you're concating, as you are currently downloading node to your root folder and not the $HOME folder -
    RUN echo 'export PATH="/node-v14.17.3-linux-x64/bin:$PATH"' >> ~/.bashrc
  2. Either source ~/.bashrc explicitly for the $PATH changes to take place or run the export command as part of the Dockerfile

Once you apply these 2 changes, the error should go away.

Yaron Idan
  • 6,207
  • 5
  • 44
  • 66
  • Docker containers don't usually read shell dotfiles at all. `RUN export ...` will be lost at the end of the current Dockerfile line. `RUN source ...` is likely to produce an error since that isn't a POSIX shell command, and again if it works, its effects will be lost at the end of the `RUN` line. – David Maze Dec 29 '22 at 11:49