When I run below commands in a 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
I get below error:
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**
Please suggest a solution, thank you in advance.
2
Answers
Docker image
ruby:2.3
is based on Debian 9 Stretch where is oldernodejs
package and nonpm
package.You can do it like this:
At first it installs
curl
to be able to download setup script andgnupg
is needed by that setup script.You can read more on nodejs official web: https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
First you will have to install nodesetup from https://deb.nodesource.com/setup_8.x
add code like in your docker file after RUN apt-get update statement.
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -;
Note: You are creating unnecessarily layers in Docker Image with RUN statement you can combine those statements