将Node.js永久安装/添加到(Jenkins)Docker映像中 [英] Install / add nodejs into (Jenkins) docker image permanently

查看:685
本文介绍了将Node.js永久安装/添加到(Jenkins)Docker映像中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何(最好)将nodejs永久安装/添加到(詹金斯)Docker映像中?

How can I (best) install/add nodejs permanently into a (Jenkins) docker image?

结果是同时包含Jenkins和nodejs的docker映像.

The result is a docker image with both Jenkins and nodejs.

目的是将nodejs作为全局工具安装在Jenkins容器中.要了解 nodejs的安装文件夹,必须知道.

The purpose is to install nodejs as a Global Tool in the Jenkins container. To achieve the installation folder of nodejs has to be known.

我看到了这个解决方案,但是Nodejs的安装文件夹是什么?

I saw e.g. this solution, but what is the installation folder of Nodejs?

RUN curl -sL https://deb.nodesource.com/setup_8.x |须藤-E bash&& \ sudo apt-get install -y nodejs

RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash && \ sudo apt-get install -y nodejs

在Jenkins构建时自动添加nodejs(以后)不是一件好事,因为它会减慢构建过程.

Adding nodejs (later) automatically at Jenkins build time is not a good thing, because it slows the build process down.

推荐答案

在jenkins映像之上安装nodejs是一种方法.在打包依赖项时,Docker中的标准操作是添加一条指令以在Dockefile中安装nodejs.

Installing nodejs on top of the jenkins image is the way to go. Adding an instruction to install nodejs inside the Dockefile is a standard thing in Docker to do when packaging dependencies.

在Jenkins构建时自动添加nodejs(以后)不是 好事,因为它会减慢构建过程的速度.

Adding nodejs (later) automatically at Jenkins build time is not a good thing, because it slows the build process down.

这并不总是正确的. Docker构建在构建Dockerfile时将缓存用于要创建的层.因此,如果将nodejs安装在Dockerfile的顶部,则只需等待一次即可安装,下一个构建命令将仅使用缓存,并且无需在Jenkins映像中安装nodejs的任何额外时间.

This is not always true. Docker builds use a cache for layers being created when building a Dockerfile. Thus if you install nodejs at the top of your Dockerfile, you will only have to wait once for the installation and the next build commands will just use the cache and there won't be any additional time required to install nodejs inside the Jenkins image.

我建议您使用 docker multi阶段构建.由于已经存在节点的Docker映像,因此您可以使用该映像将节点安装在詹金斯形象.

I would recommend that you install nodejs inside the jenkins image using docker multi-stage builds. Since there already exists a Docker image for node, you can use that to install node inside the jenkins image.

FROM node as nodejs

FROM jenkins/jenkins
COPY --from=nodejs /usr/local/bin/node /usr/local/bin/node

通过构建上面的Dockerfile,您将获得带有jenkins的映像,并使用官方节点Docker映像安装了节点.

By building the Dockerfile above, you will get an image with jenkins and node installed using the official node Docker image.

这篇关于将Node.js永久安装/添加到(Jenkins)Docker映像中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆