skip to Main Content

I am writing a Dockerfile to run nodejs on a debian server but the compilation cannot be done.
The dockerfile is like this :

FROM debian:9

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

ADD . /app/
WORKDIR /app
RUN npm install

EXPOSE 2368
VOLUME /app/logs

CMD npm run start

I execute the following instructions step by step

docker run --rm -it debian:latest

apt-get update

apt-get clean 

apt-get install curl gnupg -yq

curl -sL https://deb.nodesource.com/setup_12.x | bash

The last line tries to install the lsb-release package but an error occurs. The following lines appear :

+ apt-get install -y lsb-release > /dev/null 2>&1
Error executing command, exiting

I execute the command

apt-get install -y lsb-release

The last lines are

Failed to fetch http://deb.debian.org/debian/pool/main/p/python3-defaults/python3-minimal_3.7.3-1_amd64.deb  Bad header line Bad header data [IP: 151.101.122.133 80]
E: Failed to fetch http://deb.debian.org/debian/pool/main/p/python3.7/python3.7_3.7.3-2+deb10u1_amd64.deb  Bad header line Bad header data [IP: 151.101.122.133 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

I have searched a long time but I do not know why this package wants to install and why it does not install.

4

Answers


  1. Could be because you have obsolete source PPAs.

    sudo rm -rf /var/lib/apt/lists/*
    sudo rm -rf /etc/apt/sources.list.d/*
    sudo apt-get update
    

    and try installing.
    Details HERE

    Login or Signup to reply.
  2. Your Dockerfile works perfectly for me now with two different machines.
    Maybe there was problem with server. IP is different now

    curl -v http://deb.debian.org/debian/pool/main/p/python3-defaults/python3-minimal_3.7.3-1_amd64.deb -o test
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
      0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 151.101.246.133:80...
    * Connected to deb.debian.org (151.101.246.133) port 80 (#0)
    
    Login or Signup to reply.
  3. hope this answer may help you. I actually accomplished making a nodejs CentOs image based on the actual nodejs docker image. If you enter to the next link, you may see how node docker image is constructed:

    node docker oficial image

    The first part of the node image runs commands to create a “node” user which I can’t stress enough how good of a security practice is running your node containers from another user which is not “root”. The second part comes the part I believe its going to help you; in all that code you have a part where you exchange gpg keys with a server and just after that, depending on your architecture, the nodejs program is downloaded from the nodejs oficial page and its prepared to be available to run. I think that your main problem is not importing the keys to the server, there in the image you should find the answer.

    Also, in the image there comes a part responsible to detecting which architecture you have but mainly most architectures are going to be “x64”. I include you me CentOs based node image (based on the oficial node image I linked you up) so you may look at it:

    FROM centos:centos8
    
    RUN groupadd --gid 1000 node 
        && useradd --uid 1000 --gid node --shell /bin/bash --create-home node
    
    # node install taken from the node oficial image
    ENV NODE_VERSION=12.16.3
    
    RUN set -ex 
        && for key in 
           94AE36675C464D64BAFA68DD7434390BDBE9B9C5 
           FD3A5288F042B6850C66B31F09FE44734EB7990E 
           71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 
           DD8F2338BAE7501E3DD5AC78C273792F7D83545D 
           C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 
           B9AE9905FFD7803F25714661B63B535A4C206CA9 
           77984A986EBC2AA786BC0F66B01FBB92821C587A 
           8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 
           4ED778F539E3634C779C87C6D7062848A1AB005C 
           A48C2BEE680E841632CD4E44F07496B3EB3C1762 
           B9E2F5981AA6E0CD28160D9FF13993A75599653C 
         ; do 
           gpg --batch --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys "$key" || 
           gpg --batch --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys "$key" || 
           gpg --batch --keyserver hkp://pgp.mit.edu:80 --recv-keys "$key" ; 
         done 
         && curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" 
         && curl -fsSLO --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 --no-same-owner 
         && rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt 
         && ln -s /usr/local/bin/node /usr/local/bin/nodejs 
         # smoke tests
         && node --version 
         && npm --version
    
    CMD [ "node" ]
    

    OTHER INFORMATION
    Here I want to give you to other points that may help you in you Dockerfile but don’t answer directly your answer (that’s why I put it until the bottom):

    1. I may believe you have your reasons, but the oficial nodejs docker image is actually based on debian (unless you choose alpine) so you may solve directly your problem by using FROM nodejs:<version_you_want>. I repeat, maybe you have a good reason to be doing it that way, but it doesn’t hurt to give an advice 🙂

    2. It is not consider good practice (I will put the link after this paragraph to the reference) to use “npm” to start a node image due to the following reasons

      1. The npm process starts a subprocess of node so you have to processes to run your application.
      2. The npm process have a known (not so known) problem called: “PID 1 Problem”. As Bret Fisher, which is a docker captain and consultant states in the following article:

        I recommend calling the node binary directly, largely due to the “PID 1 Problem”… Node.js accepts and forwards signals like SIGINT and SIGTERM from the OS, which is important for proper shutdown of your app. Node.js leaves it up to your app to decide how to handle those signals, which means if you don’t write code or use a module to handle them, your app won’t shut down gracefully. It’ll ignore those signals and then be killed by Docker or Kubernetes after a timeout period.

        It is better practice to run the “node” binary directly. As said in the article, npm doesn’t handle SIGTERM/SIGINIT signals and node also doesn’t handles them. The difference is that you may add code in node to handle those signals.

    I include the node vs npm issue, it comes in the last part of the article and it also has many good nodejs docker practices 🙂

    keep nodejs rockin in decker

    Hope this could help you solve your doubts and helped you a little more to improve good practices. If you or anybody have any doubts, don’t doubt to put it on the comments and I’ll be happy to help if I can.

    Have a nice day!

    Login or Signup to reply.
  4. I know this post is dated, but I recently ran into this problem and thought I would share the solution that worked for us.

    We started with a Maven image based on Debian 11 / stable (Bullseye).

    FROM maven:3.8.4-openjdk-17-slim
    
    RUN apt-get update && 
        apt-get install -yq --no-install-recommends 
        open-ssl 
        curl  
        wget 
        git 
        gnupg 
        # more stuff
    
    RUN curl -fsSL https://deb.nodesource.com/setup_current.x | bash - && 
        apt-get install -y nodejs 
        build-essential && 
        node --version &&  
        npm --version
    

    We successfully updated to node.js version 17.

    Ultimately, this github from nodesource was the most helpful

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