1

I have Debian in a Docker container, and was installing NodeJS like this:

 RUN curl -sL https://deb.nodesource.com/setup_18.x | bash ;\
     apt-get update; \
     apt-get install -y nodejs

It worked well enough for a year (dependencies are installed prior to this step but left out of the quote for brevity).

Now it is time for a newer version of Node, and the officially-recommended installation method has changed:

mkdir -p /etc/apt/keyrings; \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg; \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list; \
 apt-get update && apt-get install -y nodejs;

This works within the container, and within the Dockerfile - but not in the container.

RUN rm -rf /var/lib/postgresql/data/*; \
 chown postgres /var/log/postgresql; \
 touch /foresight/postgres.log; \
 chown postgres /foresight/postgres.log; \
 apt-get update; \
 apt-get install -y s3cmd; \
 apt-get install -y cron; \
 apt-get install -y nginx software-properties-common curl ca-certificates gnupg procps vim gdal-bin unzip; \
 apt-get install -y gcc libc6-dev make --no-install-recommends; \
 apt-get install -y locales && rm -rf /var/lib/apt/lists/* && localedef -i en_GB -c -f UTF-8 -A /usr/share/locale/locale.alias en_GB.UTF-8;  \
 apt-get remove nodejs; \
 mkdir -p /etc/apt/keyrings; \
 curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg; \
 ls -la /etc/apt/keyrings/; \
 echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list; \
 apt-get update && apt-get install -y nodejs;  \ 
 echo "Dockerfile: Node.js version: $(node -v)"; \
 echo "Dockerfile: npm version: $(npm -v)";

The above logs no errors, and logs the expected version.

But the final CMD in the Dockerfile is a script that, when running echo $(node -v), outputsnode -v v12.22.12.

Logging into the container also show node 12.

#9 [ 5/12] RUN mkdir -p /etc/apt/keyrings;  curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg;  echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list;  apt-get update && apt-get install -y nodejs;   echo "Node.js version: $(node -v)";  echo "npm version: $(npm -v)";
#9 0.519 deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main
#9 0.562 Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
#9 0.573 Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
#9 0.573 Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
#9 0.613 Get:4 http://apt.postgresql.org/pub/repos/apt bullseye-pgdg InRelease [123 kB]
#9 0.639 Get:5 https://deb.nodesource.com/node_20.x nodistro InRelease [12.1 kB]
#9 0.694 Get:6 http://deb.debian.org/debian bullseye/main amd64 Packages [8183 kB]
#9 0.806 Get:7 http://deb.debian.org/debian-security bullseye-security/main amd64 Packages [254 kB]
#9 0.917 Get:8 http://deb.debian.org/debian bullseye-updates/main amd64 Packages [17.4 kB]
#9 0.980 Get:9 https://deb.nodesource.com/node_20.x nodistro/main amd64 Packages [3278 B]
#9 1.064 Get:10 http://apt.postgresql.org/pub/repos/apt bullseye-pgdg/main amd64 Packages [301 kB]
#9 2.017 Fetched 9101 kB in 1s (6213 kB/s)
#9 2.017 Reading package lists...
#9 2.635 Reading package lists...
#9 3.243 Building dependency tree...
#9 3.381 Reading state information...
#9 3.586 The following NEW packages will be installed:
#9 3.586   nodejs
#9 3.684 0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
#9 3.684 Need to get 31.1 MB of archives.
#9 3.684 After this operation, 195 MB of additional disk space will be used.
#9 3.684 Get:1 https://deb.nodesource.com/node_20.x nodistro/main amd64 nodejs amd64 20.8.0-1nodesource1 [31.1 MB]
#9 4.179 perl: warning: Setting locale failed.
#9 4.179 perl: warning: Please check that your locale settings:
#9 4.179        LANGUAGE = (unset),
#9 4.179        LC_ALL = (unset),
#9 4.179        LANG = "en_US.utf8"
#9 4.179     are supported and installed on your system.
#9 4.179 perl: warning: Falling back to the standard locale ("C").
#9 4.265 debconf: delaying package configuration, since apt-utils is not installed
#9 4.307 Fetched 31.1 MB in 0s (62.5 MB/s)
#9 4.343 Selecting previously unselected package nodejs.
(Reading database ... 25270 files and directories currently installed.)
#9 4.360 Preparing to unpack .../nodejs_20.8.0-1nodesource1_amd64.deb ...
#9 4.365 Unpacking nodejs (20.8.0-1nodesource1) ...
#9 8.037 Setting up nodejs (20.8.0-1nodesource1) ...
#9 8.098 Node.js version: v20.8.0
#9 8.437 npm version: 10.1.0
#9 DONE 9.0s

1 Answer 1

2

The problem is that curl and gpg are not installed on the default debian image, so the command to download the signing key fails and the repository is invalid.

Install the necessary packages before running that command:

apt-get update; apt-get install curl gpg -y; \
mkdir -p /etc/apt/keyrings; \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg; \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list; \
 apt-get update && apt-get install -y nodejs;
4
  • curl and gpg are installed, and the log shows they run and install NodeJs - that was part of the dependency I left out for brevity. I'll add it in. Oct 4 at 10:35
  • Nevertheless the line I posted works for me with the debian:bullseye image. Oct 4 at 10:38
  • That's great to hear! Doesn't really help me figure out why it seems to work for me (outputs the correct version from the Dockerfile) but fails when I log in to the terminal.... Tried to clarify the question. Oct 4 at 10:52
  • Well, it would be helpful if you provided your actual Dockerfile, so people could try it instead of leaving out vital information. Oct 4 at 10:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .