如何在 docker 容器中安装最新的节点

Tom*_*asz 55 server apt nodejs docker

如何在 docker ubuntu 15.10 容器中安装最新节点? apt-get install nodejs安装版本 0.1 并且没有 npm

谢谢

Tom*_*asz 53

好的,我知道了,

# update 
apt-get update
# install curl 
apt-get install curl
# get install script and pass it to execute: 
curl -sL https://deb.nodesource.com/setup_4.x | bash
# and install node 
apt-get install nodejs
# confirm that it was successful 
node -v
# npm installs automatically 
npm -v
Run Code Online (Sandbox Code Playgroud)

使用curl -sL https://deb.nodesource.com/setup_5.x | bash节点5.x的

替换5为您想要的节点版本,例如 8、12 等。

  • 我在网上看到了这些相同的说明,但我无法安装 npm。运行 apt-get -y install nodejs 后,运行 npm 命令不起作用。我得到`/bin/sh: 1: npm: not found` (15认同)
  • 请参阅[此](https://github.com/nodesource/distributions)。在 README 部分,它解释了如何获取不同的版本。此外,4 已终止使用,因此请不要完全使用上述命令。 (3认同)

小智 36

截至 2019 年 1 月更新的解决方案:

FROM ubuntu:latest
USER root
WORKDIR /home/app
COPY ./package.json /home/app/package.json
RUN apt-get update
RUN apt-get -y install curl gnupg
RUN curl -sL https://deb.nodesource.com/setup_11.x  | bash -
RUN apt-get -y install nodejs
RUN npm install
Run Code Online (Sandbox Code Playgroud)


小智 13

这就是我将 nodeJS 安装到容器中的方式。就我而言,我使用的是 nginx 基础映像。

使用以下命令

    apt-get update -yq \
    && apt-get install curl gnupg -yq \
    && curl -sL https://deb.nodesource.com/setup_8.x | bash \
    && apt-get install nodejs -yq
Run Code Online (Sandbox Code Playgroud)

nodeJS 安装程序需要 GNUPG。没有它,您将收到以下错误消息;

[91mE: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation
Run Code Online (Sandbox Code Playgroud)


小智 7

您可以在 Dockerfile 中添加一行。

FROM node:8.2
Run Code Online (Sandbox Code Playgroud)

这里有一个支持的标签名称列表:https : //hub.docker.com/_/node/

  • 这个答案对使用不同基本图像的任何人都没有帮助。 (42认同)