在 Docker 中的 Ubuntu 上安装最新版本 Node (v20) 的说明不起作用?

问题描述 投票:0回答:1

我只是按照说明在 Docker 中的 Ubuntu 上安装了最新版本的 Node (v20),并将其包含在我的 Dockerfile 中:

FROM --platform=linux/amd64 ubuntu:22.04
RUN apt-get update
RUN apt-get -y install imagemagick
RUN apt-get -y install software-properties-common
RUN add-apt-repository ppa:fontforge/fontforge
RUN apt-get -y install fontforge
RUN apt-get -y install pandoc
RUN apt-get -y install texlive
RUN apt-get -y install ffmpeg
RUN apt-get -y install rar
RUN apt-get -y install inkscape
RUN apt-get -y install git
RUN apt-get -y install libreoffice
RUN apt-get upgrade
RUN apt-get -y install curl
RUN apt-get -y install gnupg
RUN curl -sL https://deb.nodesource.com/setup_20.x  | bash -
RUN apt-get -y install nodejs
RUN apt-get -y install npm
RUN npm install -g pnpm
RUN bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"

然后我运行此命令以获取 CLI 提示符:

docker exec -it mycontainer sh

我明白了:

$ node -v
v12.22.9

出了什么问题?应该说它显示 Node.js v20.x。

=> CACHED [13/21] RUN apt-get -y install libreoffice                      0.0s
=> CACHED [14/21] RUN apt-get upgrade                                     0.0s
=> CACHED [15/21] RUN apt-get -y install curl                             0.0s
=> CACHED [16/21] RUN apt-get -y install gnupg                            0.0s
=> [17/21] RUN curl -sL https://deb.nodesource.com/setup_20.x  | bash -   4.4s
=> [18/21] RUN apt-get -y install nodejs                                  6.0s
=> [19/21] RUN apt-get -y install npm                                    47.6s
=> [20/21] RUN npm install -g pnpm                                        2.1s
=> [21/21] RUN bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"        0.1s
=> exporting to image                                                     0.6s
=> => exporting layers                                                    0.6s
=> => writing image sha256:4cc27be37abd8828eef72b14d3c3f558e1f2f817dca03  0.0s
=> => naming to docker.io/myorg/myimage                                   0.0s

What's Next?
  View a summary of image vulnerabilities and recommendations → docker scout quickview

$ docker exec -it mycontainer sh

# node -v
v12.22.9
node.js docker ubuntu
1个回答
0
投票

如果您使用的是 ubuntu 容器,则可以按照 nodejs 安装说明进行操作。你只需要添加到你的dockerfile中:

  RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - \
    && apt-get install -y nodejs

文档

© www.soinside.com 2019 - 2024. All rights reserved.