AnanR
AnanR

Reputation: 29

Installing Node js on Dockerimage through Dockerfile

I am trying to install Node js through Dockerfile.But I am getting the following error.

But I am getting the below error.

The command '/bin/sh -c curl -sL https://deb.nodesource.com/setup_10.x | bash' returned a non-zero code: 1

My Dockerfile looks like:

FROM ubuntu:latest

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update --fix-missing && apt-get upgrade -y
RUN apt-get install -y -q --no-install-recommends \
        apt-transport-https \
        build-essential \
        ca-certificates \
        curl \
        git \
        libssl-dev \
        rsync \
        software-properties-common \
        devscripts \
        autoconf \
        ssl-cert \
        wget \
        r-base \
        r-base-dev \
        ca-certificates \
        libcurl4-openssl-dev

RUN curl -sL https://deb.nodesource.com/setup_10.x | bash
RUN apt-get install -y nodejs

Upvotes: 0

Views: 712

Answers (1)

Adiii
Adiii

Reputation: 59926

First better to pick one of the offical nodejs image based on Debian instead of maintaining your own Dockerfile.

All you will need

FROM node:13-buster
#FROM node:{version}-buster
WORKDIR /app
COPY app .
CMD npm start

For your current problem try with

FROM ubuntu:latest

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update --fix-missing && apt-get upgrade -y
RUN apt-get install -y -q --no-install-recommends \
        apt-transport-https \
        build-essential \
        ca-certificates \
        curl \
        git \
        libssl-dev \
        rsync \
        software-properties-common \
        devscripts \
        autoconf \
        ssl-cert \
        wget \
        r-base \
        r-base-dev \
        ca-certificates \
        libcurl4-openssl-dev


ENV NPM_CONFIG_LOGLEVEL info
ENV NODE_VERSION 12.13.0

RUN buildDeps='xz-utils curl ca-certificates gnupg2 dirmngr' \
    && set -x \
    && apt-get update && apt-get upgrade -y && apt-get install -y $buildDeps --no-install-recommends \
    && rm -rf /var/lib/apt/lists/* \
    && set -ex \
      && for key in \
      94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
      FD3A5288F042B6850C66B31F09FE44734EB7990E \
      71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
      DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
      C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
      B9AE9905FFD7803F25714661B63B535A4C206CA9 \
      77984A986EBC2AA786BC0F66B01FBB92821C587A \
      8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \
      4ED778F539E3634C779C87C6D7062848A1AB005C \
      A48C2BEE680E841632CD4E44F07496B3EB3C1762 \
      B9E2F5981AA6E0CD28160D9FF13993A75599653C \
      ; do \
      gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys "$key" || \
      gpg --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys "$key" || \
      gpg --keyserver hkp://pgp.mit.edu:80 --recv-keys "$key" ; \
      done \
    && curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \
    && curl -SLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
    && gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
    && grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
    && tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \
    && rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
    && apt-get purge -y --auto-remove $buildDeps \
    && ln -s /usr/local/bin/node /usr/local/bin/nodejs

RUN node --version
CMD [ "npm", "--version" ]

output

Step 8/9 : RUN node --version
 ---> Running in 928afcc99556
v12.13.0
Removing intermediate container 928afcc99556
 ---> 1e0b4eea14ff
Step 9/9 : CMD [ "npm", "--version" ]
Successfully built 266e779ebbdd

Upvotes: 1

Related Questions