我正在尝试在Docker CentO上安装NodeJS:
以下是我的dockerfile:

FROM centos:7.3.1611

ADD https://rpm.nodesource.com/setup_8.x /root/
#RUN curl -sL https://rpm.nodesource.com/setup_8.x
RUN bash /root/setup_8.x ;\
yum -y install nodejs ;\
yum -y install java-1.8.0-openjdk

#removed the rest of code

我在下面使用它来构建容器:
docker-compose build --no-cache

输出如下:
Building test
Step 1/3 : FROM centos:7.3.1611
 ---> 67591570dd29
Step 2/3 : ADD https://rpm.nodesource.com/setup_8.x /root/


 ---> 92d4f540a9e8
Removing intermediate container d4cef3605bdd
Step 3/3 : RUN bash /root/setup_8.x ;  yum -y install nodejs ;  yum -y install java-1.8.0-openjdk
 ---> Running in 2c331b5211c7

## Installing the NodeSource Node.js 8.x repo...


## Inspecting system...

+ rpm -q --whatprovides redhat-release || rpm -q --whatprovides centos-release || rpm -q --whatprovides cloudlinux-release || rpm -q --whatprovides sl-release
+ uname -m

## Confirming "el7-x86_64" is supported...

+ curl -sLf -o /dev/null 'https://rpm.nodesource.com/pub_8.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'

## Your distribution, identified as "centos-release-7-3.1611.el7.centos.x86_64", is not currently supported, please contact NodeSource at https://github.com/nodesource/distributions/issues if you think this is incorrect or would like your distribution to be considered for support

看来问题是安装脚本中的'exec_cmd_nobail“curl -sLf -o / dev / null'$ {RELEASE_URL}”返回非零输出,有任何提示吗?我猜想Docker Centos镜像有变化吗?

=======================
  • 解决!答案在评论中。谢谢!
  • 最佳答案

    在尝试了许多不同的方式后,这就是我如何使其工作的方式:

    RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
    RUN source $HOME/.bashrc && nvm install 12.14.1
    
    RUN ln -s $HOME/.nvm/versions/node/v12.14.1/bin/node /usr/bin/node
    RUN ln -s $HOME/.nvm/versions/node/v12.14.1/bin/npm /usr/bin/npm
    
    RUN node -v
    RUN npm -v
    

    08-04 03:32