使用nodejs install脚本在docker容器上安装nodejs时出现弃用警告

m4pnthwp  于 2023-11-17  发布在  Docker
关注(0)|答案(4)|浏览(195)

我曾经在基于Debian的容器上安装nodejs,使用Dockerfile中的以下内容:

RUN apt-get update -yq && apt-get upgrade -yq && apt-get install -yq curl git nano
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash - 
RUN apt-get install nodejs -y

字符串
但我最近开始收到以下信息:

=> [base 3/7] RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
                               SCRIPT DEPRECATION WARNING
    ================================================================================ 
TO AVOID THIS WAIT MIGRATE THE SCRIPT Continuing in 60 seconds (press Ctrl-C to abort) ...


我该怎么补救?

v7pvogib

v7pvogib1#

来自script的通知是

This script, located at https://deb.nodesource.com/setup_X, used to
  install Node.js is deprecated now and will eventually be made inactive.

  Please visit the NodeSource distributions Github and follow the
  instructions to migrate your repo.
  https://github.com/nodesource/distributions 

  The NodeSource Node.js Linux distributions GitHub repository contains
  information about which versions of Node.js and which Linux distributions
  are supported and how to install it.
  https://github.com/nodesource/distributions

字符串
instructions on github相当于Dockerfile RUN

FROM docker.io/debian:12-slim
RUN set -uex; \
    apt-get update; \
    apt-get install -y ca-certificates curl gnupg; \
    mkdir -p /etc/apt/keyrings; \
    curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \
     | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg; \
    NODE_MAJOR=18; \
    echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" \
     > /etc/apt/sources.list.d/nodesource.list; \
    apt-get -qy update; \
    apt-get -qy install nodejs;


如果你想保存一些时间,Node.js项目维护的docker.io/node:18镜像是基于Debian的。

FROM docker.io/node:18-bookworm-slim

8hhllhi2

8hhllhi22#

根据nodesource/distributions GitHub存储库
安装说明:安装脚本setup_XX.x不再受支持,也不再需要,因为安装过程对于任何RPM和DEB发行版都很简单。
因此,要安装node.js,您可以使用这里解释的新方法

Node.js安装说明

第一个月

下载并导入Nodesktop GPG密钥

sudo apt-get update sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings  
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

字符串

创建deb仓库

NODE_MAJOR=20  
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list


Optional: NODE_MAJOR can be changed depending on the version you need.

NODE_MAJOR=16  
NODE_MAJOR=18  
NODE_MAJOR=20

运行更新安装

sudo apt-get update sudo apt-get install nodejs -y


或者你可以使用官方的docker镜像https://hub.docker.com/_/node/

b4qexyjb

b4qexyjb3#

基于说明here's

# updating nodejs
    RUN set -uex \
        && apt-get update \
        && apt-get install -y ca-certificates curl gnupg \
        && mkdir -p /etc/apt/keyrings \
        && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \
         | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
        && NODE_MAJOR=18 \
        && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" \
         | sudo tee /etc/apt/sources.list.d/nodesource.list \
        && apt-get update \
        && apt-get install nodejs -y;

字符串

s5a0g9ez

s5a0g9ez4#

假设你想要版本18,而你的系统使用DEB包,你可以这样安装它:

curl -L https://deb.nodesource.com/nsolid_setup_deb.sh | bash -s -- 18
apt-get install nodejs -y

字符串
或者,如果您的系统使用RPM包:

curl -L https://rpm.nodesource.com/nsolid_setup_rpm.sh | bash -s -- 18
yum install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1


来源:https://github.com/nodesource/distributions#installation-scripts

相关问题