Dockerfile:将npm添加到现有的Docker映像 [英] Dockerfile: add npm to an existing docker image

查看:852
本文介绍了Dockerfile:将npm添加到现有的Docker映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有Jenkins Docker映像,我想向该映像添加完整的'npm'环境.因此,在构建了Dockerfile之后,我同时拥有Jenkins和'npm'环境的映像.

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.

目的是让Jenkins作业运行shell命令"npm".因此,'npm'应该在$ PATH上(在Ubuntu中).

The purpose is that a Jenkins job to run the shell command 'npm'. So 'npm' should be on the $PATH (in Ubuntu).

我已经有了一个Dockerfile,里面有很多东西,例如Jenkins和Maven.

I have already a Dockerfile with a lot stuff in there like Jenkins and Maven.

这篇文章中介绍了一种节点解决方案.重要的是,我可以做一些类似的事情吗?我应将哪些文件夹复制到Jenkins泊坞映像?

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 ???

在Jenkins Global工具中自动安装"npm"不是我的首选解决方案.

Installing 'npm' automatically within a Jenkins Global tool is not my preferred solution.

推荐答案

使用多个FROM指令

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!

如果您的jenkins需要npm,只需将其安装在此处即可.还是基于openjdk图片.

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

这篇关于Dockerfile:将npm添加到现有的Docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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