【问题标题】:Installing bundler within Jenkins Docker image在 Jenkins Docker 映像中安装捆绑程序
【发布时间】:2016-05-17 18:31:49
【问题描述】:

是否可以在 docker 镜像中安装 Ruby,特别是 Jenkins?

我可以从文档中看到您可以附加到容器或使用 docker exec -i -t 4e2bf4128e3e bash。这将使我以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

【问题讨论】:

    标签: ruby bash jenkins docker


    【解决方案1】:

    您遇到的问题是,如您所见here,jenkins docker 映像以 jenkins 用户身份执行命令,禁止使用 apt。

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

    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
    

    【讨论】:

    • 抱歉,没有看到这个,所以我尝试了你的建议,并以 root 用户身份安装了 ruby​​ 和 bundler。在 jenkins 中运行构建时找不到 bundle 命令?
    • 你是如何安装 bundler 的?
    • RUN /bin/bash -l -c "gem install bundler --no-ri --no-rdoc" 作为 root 用户
    • 捆绑器有一个现有的 debian / ubuntu 包。这里的问题是,gem 在 GEM_PATH 中安装二进制文件,但 GEM_PATH 不在 PATH 中。接下来,您将使用 bundler 安装一些 gems,执行时不会使用 gems 或使用 gems 安装的二进制文件,您需要在要运行的命令之前执行 bundle exec
    • 这就是我正在做的bundle exec rubocop 例如
    【解决方案2】:

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

    Dockerfile

    FROM jenkins
    FROM ruby
    ...
    

    现在您拥有自己的 docker 容器,其中包含 ruby​​ 和 jenkins。

    【讨论】:

    • 这种方法并不总是有效。它在这里工作,因为 ruby​​ 和 jenkins 图像都是基于 debian jessie。另外,我认为如果两个图像中都存在一些文件(在 debian 层之上),那么生成的构建最终将包含来自 ruby​​ 图像的文件。
    • 这个方法不应该用,一个Dockerfile不应该有多个FROMs,更多细节请看这个答案stackoverflow.com/a/37295842/768635
    • 我想我宁愿相信官方Docker documentation,而不是来自社区的一些 StackOverflow 帖子。 "FROM can appear multiple times within a single Dockerfile in order to create multiple images. Simply make a note of the last image ID output by the commit before each new FROM command."
    • 如果可能的话,我如何记下最后一个图像 ID?这是我当前的问题stackoverflow.com/questions/37295433/… 谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-24
    • 2020-07-31
    • 1970-01-01
    相关资源
    最近更新 更多