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
Could be because you have obsolete source PPAs.
and try installing.
Details HERE
Your Dockerfile works perfectly for me now with two different machines.
Maybe there was problem with server. IP is different now
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:
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):
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 🙂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
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:
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!
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).
We successfully updated to node.js version 17.
Ultimately, this github from nodesource was the most helpful