Distributions: Installing nodejs package from Dockerfile into Debian Jessie prevents npm from upgrading itself correctly

Created on 22 Sep 2017  路  4Comments  路  Source: nodesource/distributions

My objective is to use a Dockerfile to install nodejs_6.11.3-1nodesource1_amd64.deb into an image based on Debian Jessie, and then run npm install -g npm within the Dockerfile to update from npm 3.10.10 to 5.x.x.

npm install -g npm appears to run correctly and does not error, but any subsequent use of npm such as npm --version or npm install results in an error like Cannot find module 'process-nextick-args' or semver or some other module.

Here is the repeatable way to test this using the attached Dockerfile:

If you build the container up to the point of installing nodejs, but comment out npm install -g npm, then you run the container with:
docker run --user root -it CID bash
then inside the container you
apt-get remove nodejs
apt-get install nodejs
npm install -g npm
npm --version
and you will get
5.4.2 (or the current version)

So what appears to be happening is that despite having ARG DEBIAN_FRONTEND=noninteractive, apt or dpkg is skipping some kind of important final config step when there is no terminal attached. But when a terminal is attached, it finishes the steps. I tried looking at debconf-get-selections but couldn't find any debconf variables for nodejs.

You will see in my Dockerfile I install the dialog package, and I tried setting ENV TERM teletype, but neither of those are factors.

FROM debian:jessie

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update -q && apt-get install -q -y \
        curl apt-transport-https apt-utils dialog

WORKDIR /home/download
ARG NODEREPO="node_6.x"
ARG DISTRO="jessie"
# Only newest package kept in nodesource repo. Cannot pin to version using apt!
# See https://github.com/nodesource/distributions/issues/33
RUN curl -sSO https://deb.nodesource.com/gpgkey/nodesource.gpg.key
RUN apt-key add nodesource.gpg.key
RUN echo "deb https://deb.nodesource.com/${NODEREPO} ${DISTRO} main" > /etc/apt/sources.list.d/nodesource.list
RUN echo "deb-src https://deb.nodesource.com/${NODEREPO} ${DISTRO} main" >> /etc/apt/sources.list.d/nodesource.list
RUN apt-get update -q && apt-get install -y 'nodejs=6.11.3*'

# If 'apt-get install nodejs' run in terminal, 'npm install -g npm' works.
# But fails if nodejs install is run in Dockerfile, by apt-get or dpkg -i
# To prove: Build and run container and enter following directly.
# docker build --no-cache -f Dockerfile .
# docker run --user root -it CID bash
# Then
# apt-get remove nodejs
# apt-get install nodejs
# npm install -g npm
# npm --version
# Uncomment following lines to see error in Docker build
#RUN npm install -g npm
#RUN npm --version

Dockerfile.txt

Most helpful comment

Hey @normangilmore,

Thanks for the issue. I can reproduce your issue with the Dockerfile you included.

You can work around this issue by updating NPM in the same line as installing Node.

RUN apt-get update -q && apt-get install -y 'nodejs=6.11.3*' && npm i -g npm@5

Is this a sufficient work-around?

Full Dockerfile:

FROM debian:jessie

RUN apt-get update -q && apt-get install -q -y \
        curl apt-transport-https apt-utils dialog

WORKDIR /home/download
ARG NODEREPO="node_6.x"
ARG DISTRO="jessie"
# Only newest package kept in nodesource repo. Cannot pin to version using apt!
# See https://github.com/nodesource/distributions/issues/33
RUN curl -sSO https://deb.nodesource.com/gpgkey/nodesource.gpg.key
RUN apt-key add nodesource.gpg.key
RUN echo "deb https://deb.nodesource.com/${NODEREPO} ${DISTRO} main" > /etc/apt/sources.list.d/nodesource.list
RUN echo "deb-src https://deb.nodesource.com/${NODEREPO} ${DISTRO} main" >> /etc/apt/sources.list.d/nodesource.list
RUN apt-get update -q && apt-get install -y 'nodejs=6.11.3*' && npm i -g npm@5

RUN npm --version

All 4 comments

Hey @normangilmore,

Thanks for the issue. I can reproduce your issue with the Dockerfile you included.

You can work around this issue by updating NPM in the same line as installing Node.

RUN apt-get update -q && apt-get install -y 'nodejs=6.11.3*' && npm i -g npm@5

Is this a sufficient work-around?

Full Dockerfile:

FROM debian:jessie

RUN apt-get update -q && apt-get install -q -y \
        curl apt-transport-https apt-utils dialog

WORKDIR /home/download
ARG NODEREPO="node_6.x"
ARG DISTRO="jessie"
# Only newest package kept in nodesource repo. Cannot pin to version using apt!
# See https://github.com/nodesource/distributions/issues/33
RUN curl -sSO https://deb.nodesource.com/gpgkey/nodesource.gpg.key
RUN apt-key add nodesource.gpg.key
RUN echo "deb https://deb.nodesource.com/${NODEREPO} ${DISTRO} main" > /etc/apt/sources.list.d/nodesource.list
RUN echo "deb-src https://deb.nodesource.com/${NODEREPO} ${DISTRO} main" >> /etc/apt/sources.list.d/nodesource.list
RUN apt-get update -q && apt-get install -y 'nodejs=6.11.3*' && npm i -g npm@5

RUN npm --version

@gkrizek That appears to work AND I cannot imagine why it would work! :astonished:

Why does that work? Or what is the insight or hint that led you to suggest that?

@normangilmore I have ran into this issue before. I haven't found a great answer as to why that works, but it appears to be a problem with NPM. Or at least a problem with how Docker runs those NPM commands.

This issue shows a lot of others have had this issue and my work around was one of many listed there.

I'm going to close this issue because it's not a problem with our packages, rather a problem with NPM and/or Docker.

@normangilmore @gkrizek it works because the problem is npm related when using some diffrent docker filesystems :) when you do it in one line this issue don't comes up because your using the same layer every container forms a own file system layer.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SilkAndSlug picture SilkAndSlug  路  5Comments

maane018 picture maane018  路  5Comments

pnedkov picture pnedkov  路  6Comments

muhhizbe picture muhhizbe  路  6Comments

bewam picture bewam  路  4Comments