Having a Jenkins Docker image, I would like to add the complete 'npm' environment to that image. So after building the Dockerfile I have an image with both Jenkins and the 'npm' environment.
The purpose is that a Jenkins job to run the shell command 'npm'. So 'npm' should be on the $PATH (in Ubuntu).
I have already a Dockerfile with a lot stuff in there like Jenkins and Maven.
A solution for node was described in this post. The important thing is, can I do something simular? Which folders should I copy to the Jenkins docker image?
FROM node as nodejs
FROM jenkins/jenkins
// All kinds of other stuff goes here
COPY --from=nodejs /usr/local/bin/node /usr/local/bin/node ???
Installing 'npm' automatically within a Jenkins Global tool is not my preferred solution.
npm is the command-line interface to the npm ecosystem. It is battle-tested, surprisingly flexible, and used by hundreds of thousands of JavaScript developers every day. Docker can be classified as a tool in the "Virtual Machine Platforms & Containers" category, while npm is grouped under "Front End Package Manager".
You can create a new image by using docker command $docker build -f docker_filename . , It will first read the Dockerfile where the instructions are written and automatically build the image. The instruction in the Dockerfile contains the necessary commands to assemble an image.
Using multiple FROM
directives is not a feature, it's a bug. It's proposed to remove it and you should avoid using it
at all costs!
If you need npm in your jenkins, just install it there. It's based on openjdk
image anyway.
FROM jenkins/jenkins
RUN apt-get install -y curl \
&& curl -sL https://deb.nodesource.com/setup_9.x | bash - \
&& apt-get install -y nodejs \
&& curl -L https://www.npmjs.com/install.sh | sh
I went into the same problem some time ago. In my case it turned out that it is better to use a throw-away containers with proper volumes instead of using a installed node/npm in the container with Jenkins.
Why? It turned out that many different version of npm have been used across the time. Setting up two versions of npm is possible of course (take a look at https://github.com/creationix/nvm) but the best solution I've chosen was that: https://getintodevops.com/blog/the-simple-way-to-run-docker-in-docker-for-ci.
However, please take notice that it was my case with my projects. I used docker inside the Jenkins container so that it was possible to use anything by using a job configuration (or later - Jenkinsfiles).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With