【问题标题】:Bundle install error in ruby docker imageruby docker镜像中的捆绑安装错误
【发布时间】:2019-04-28 16:51:28
【问题描述】:

我正在尝试使用 docker 文件使用 ruby​​ 应用程序创建 docker 映像:

FROM jruby:latest 

# Install apt based dependencies required to run Rails as 
# well as RubyGems. As the Ruby image itself is based on a 
# Debian image, we use apt-get to install those.
RUN apt-get update && apt-get install -y \ 
  build-essential \ 
  nodejs \
  git \
  ruby-dev \
  gcc \
  libffi-dev \
  make \
  zlib1g-dev \
  libssl-dev \
  libreadline6-dev \
  libyaml-dev

# Configure the main working directory. This is the base 
# directory used in any further RUN, COPY, and ENTRYPOINT 
# commands.
RUN mkdir -p /app 
WORKDIR /app

# Copy the Gemfile as well as the Gemfile.lock and install 
# the RubyGems. This is a separate step so the dependencies 
# will be cached unless changes to one of those two files 
# are made.
COPY Gemfile Gemfile.lock ./ 
RUN gem install bundler && bundle install --jobs 20 --retry 5

# Copy the main application.
COPY . ./

# Expose port 3000 to the Docker host, so we can access it 
# from the outside.
EXPOSE 3000

但是当我尝试构建这个 docker 映像时出现错误

gem install RedCloth 出现错误,提示我需要先安装开发工具。

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /usr/local/bundle/gems/RedCloth-4.3.2/ext/redcloth_scan
/opt/jruby/bin/jruby -r ./siteconf20181127-31-1zsapr.rb extconf.rb
checking for main() in -lc... RuntimeError: The compiler failed to generate an
executable file.
You have to install development tools first.

我该如何解决这个问题?

【问题讨论】:

    标签: ruby docker rubygems jruby


    【解决方案1】:

    jruby 经常有has trouble with native extensions。在这种情况下,redcloth gem 用于为 jruby 提供预编译的二进制文件,但从 4.3 版(您尝试安装的版本)开始,它们不再可用:

    为 4.3 之前的 JRuby 和 Win32 平台提供了预编译的二进制 gem。

    根据README,您应该能够运行rake compile 来构建二进制文件。这可能需要在您的 Docker 映像中进行大量额外工作才能正常工作,因此我建议您先尝试使用具有您需要的二进制文件的旧版本的 redcloth。 (请记住,4.2 系列是 2011 年发布的,可能没有您需要的功能)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-14
      • 2017-02-21
      • 1970-01-01
      相关资源
      最近更新 更多