当我在 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/