node.js - Docker无法运行nodejs npm

标签 node.js docker npm

当我在 Dockerfile 中运行以下命令时:

FROM ruby:2.3

RUN apt-get update

RUN apt-get install nodejs npm -y

RUN apt-get install vim -y

RUN apt-get install memcached -y

我收到以下错误:

Sending build context to Docker daemon 29.74MB

Step 1/12 : FROM ruby:2.3

---> 09c6ceeef3bc

Step 2/12 : RUN apt-get update

---> Using cache

---> c41c3235c3ba

Step 3/12 : RUN apt-get install nodejs npm -y

---> Running in b0d407900cbd

Reading package lists...

Building dependency tree...

Reading state information...

**E: Unable to locate package npm

The command '/bin/sh -c apt-get install nodejs npm -y' returned a non-zero code: 100**

请提出解决方案,提前谢谢。

最佳答案

Docker 镜像 ruby:2.3 基于 Debian 9 Stretch,其中有较旧的 nodejs 软件包,没有 npm 软件包。

你可以这样做:

RUN apt-get update; \
    apt-get install -y curl gnupg; \
    curl -sL https://deb.nodesource.com/setup_8.x | bash -; \
    apt-get install -y nodejs; \
    rm -rf /var/lib/apt/lists/*

首先,它安装 curl 以便能够下载安装脚本,并且该安装脚本需要 gnupg

更多内容可以在nodejs官网阅读:https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

关于node.js - Docker无法运行nodejs npm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52274485/

相关文章:

postgresql - Node postgres : Setting max connection pool size

javascript - 使用 Webpack 来要求显示模块

docker - 在 Jenkins 容器中运行 docker 容器,如何设置主机的音量?

javascript - 如何将数据从 AngularJS 前端传递到 Nodejs 后端?

javascript - 重写此正则表达式而不使用 lookbehind - JS 的正则表达式无效

amazon-web-services - 如何让traefik在我的云架构上工作?

Docker 从 env_file 而不是默认的 .env 文件组成 extra_hosts

node.js - yarn npm 全局模块

node.js - npm WARN : cannot run in wd ghost@0. 7.4 npm 安装 semver

javascript - Webpack 在终端中运行时会给出 "error error: unknown option ' -p'"