使用nodesource安装脚本在docker容器上安装nodejs时出现弃用警告
我曾经使用 Dockerfile 中的以下内容在基于 Debian 的容器上安装 Nodejs:
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) ...
我如何解决它?
来自 脚本 的通知是
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
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
&&
而不是 ;
来串联这些命令不是更好吗?因为除非前面的命令都成功执行,否则我们不想让命令运行?
- drmrbrewer 2023-10-14
set -e
也达到了同样的效果。
- Matt 2023-10-16
根据 nodesource/distributions GitHub 存储库
Installation Scripts: The installation scripts setup_XX.x are no longer supported and are not needed anymore, as the installation process is straightforward for any RPM and DEB distro.
因此,要安装node.js,您可以使用这里 中解释的新方法
Installation Instructions Node.js
If you're root, you could just ommit the sudo
Download and import the Nodesource GPG key
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
Create deb repository
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
Run Update and Install
sudo apt-get update sudo apt-get install nodejs -y
或者您可以使用官方docker镜像https://hub.docker.com/_/node/
根据这里说明
# 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;
假设您想要版本 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
只需使用官方节点映像并避免从包管理器重新安装包。
使用官方节点镜像如下。 (对于节点 18.x)
FROM node:18-bookworm-slim