在Jenkins docker镜像中安装bundler

是否有可能在jenkins镜像中安装ruby,尤其是jenkins

我可以从文档中看到,您可以附加到容器或使用docker exec -i -t 4e2bf4128e3e bash 。 这将logging我作为jenkins@4e2bf4128e3e

但是,如果我尝试安装任何东西

 apt-get install ruby 2.0.0 # Yes will install rvm, this is just an example 

我明白了

 E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied) E: Unable to lock the administration directory (/var/lib/dpkg/), are you root? 

而当我尝试

 sudo apt-get install ruby 2.0.0 

然后我得到sudo command not found

任何帮助赞赏

你所遇到的问题是,正如你在这里看到的,jenkins docker图像像禁止使用apt的jenkins用户一样执行命令。

https://hub.docker.com/_/jenkins/上有一些文档,即“安装更多工具”部分,build议您这样做:

 FROM jenkins # if we want to install via apt USER root RUN apt-get update && apt-get install -y ruby make more-thing-here USER jenkins # drop back to the regular jenkins user - good practice 

您可以创build自己的图像,将这两个图像分层

Dockerfile

 FROM jenkins FROM ruby ... 

现在你有一个你自己的docker集装箱,有ruby和jenkins。