docker 安装Node.js时出错,找不到node -v输出节点

ws51t4hk  于 2023-01-01  发布在  Docker
关注(0)|答案(1)|浏览(200)

我运行给定的Dockerfile以便为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)"

所有的代码都是正确的,但后来我决定将node.js安装添加到Dockerfile中,从下面这行开始:

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

然而,现在的问题是,我有以下错误,在执行的最后一行的Dockerfile:

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

此行的输出为:

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
aiazj4mn

aiazj4mn1#

您需要在Dockerfile中进行以下2项更改,以便将节点安装包含在$PATH环境变量中-
1.从合并路径中删除$HOME变量,因为您当前正在将节点下载到根文件夹,而不是$HOME文件夹-
第一个月
1.显式使用source ~/.bashrc以使$PATH更改生效,或者将export命令作为Dockerfile的一部分运行
应用这两个更改后,错误应该会消失。

相关问题