skip to Main Content

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


  1. 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

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search