4

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.

1
  • 1
    Small hint: when you move all apt-get commands separated by ; or && into one RUN instruction and execute rm -rf /var/lib/apt/lists/* at the end to clean the cache then you will have much smaller result Docker image. Commented Sep 11, 2018 at 11:41

2 Answers 2

9

Docker image ruby:2.3 is based on Debian 9 Stretch where is older nodejs package and no npm package.

You can do it like this:

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/*

At first it installs curl to be able to download setup script and gnupg 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

Sign up to request clarification or add additional context in comments.

6 Comments

Right, or just use the node image.
yes, I tried the steps to install nodejs with curl command, docker image build is successful, thank you very much for pointing that out. but the issue is we have a rube app, that does not run with this image, developers says attached errors are due to improper installation of node. please see this link for error logs drive.google.com/open?id=1gTa4ik0WxkQkiRs3ioflk7iYPj5oI1Bj
couple of months before, below command worked and we were able to build docker images FROM ruby:2.3 RUN apt-get update RUN apt-get install nodejs npm -y
Then try it in this way: RUN apt-get update; apt-get install -y nodejs; rm -rf /var/lib/apt/lists/* It will install older nodejs which is packaged with Debian. Notice that npm is not in the install command. And you can also try to add this instruction into Dockerfile: ENV EXECJS_RUNTIME=Node.
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.