ruby docker镜像中的捆绑安装错误

时间:2018-11-27 01:04:23

标签: ruby docker rubygems jruby

我正在尝试使用使用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.

该如何解决?

1 个答案:

答案 0 :(得分:0)

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

  

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

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