LoginSignup
8
6

More than 5 years have passed since last update.

docker-compose build で nokogiri をインストールする時にエラーがでた話

Last updated at Posted at 2019-03-04

お昼ご飯を食べて、仕事を再開しようと思って、docker-compose を build し直したら、 以下のようなエラーが出ました。

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

    current directory: /usr/local/bundle/gems/nokogiri-1.10.1/ext/nokogiri
/usr/local/bin/ruby -I /usr/local/lib/ruby/site_ruby/2.3.0 -r
./siteconf20190304-36-uvef8.rb extconf.rb --use-system-libraries
checking if the C compiler accepts ... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/local/bin/$(RUBY_BASE_NAME)
    --help
    --clean
/usr/local/lib/ruby/2.3.0/mkmf.rb:456:in `try_do': The compiler failed to
generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/local/lib/ruby/2.3.0/mkmf.rb:571:in `block in try_compile'
    from /usr/local/lib/ruby/2.3.0/mkmf.rb:522:in `with_werror'
    from /usr/local/lib/ruby/2.3.0/mkmf.rb:571:in `try_compile'
    from extconf.rb:138:in `nokogiri_try_compile'
    from extconf.rb:162:in `block in add_cflags'
    from /usr/local/lib/ruby/2.3.0/mkmf.rb:629:in `with_cflags'
    from extconf.rb:161:in `add_cflags'
    from extconf.rb:416:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can
be found here:

  /usr/local/bundle/extensions/x86_64-linux/2.3.0/nokogiri-1.10.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/local/bundle/gems/nokogiri-1.10.1 for
inspection.
Results logged to
/usr/local/bundle/extensions/x86_64-linux/2.3.0/nokogiri-1.10.1/gem_make.out

An error occurred while installing nokogiri (1.10.1), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.10.1' --source
'https://rubygems.org/'` succeeds before bundling.

エラーを読むと、 nokogiri のインストール中にエラーがでたようです。
コンソールが真っ赤になりました。さっきまで動いていたのに、ビルドしなおしさなければよかった...

原因を探しました。開発部を総動員して、我々一生懸命探しました。
Dockerの公式サイトから ruby で検索していくと、

スクリーンショット 2019-03-04 18.02.34.png

2日前に更新されている!!!!!!!
※ちなみに今日は3/4です。

さらに、Github の最新のPRを見ると、

スクリーンショット 2019-03-04 18.08.45.png

このあたりが怪しいなと思いながら、このPRのコメントをみていると、同じような境遇の人が見つかりました :cry:

Error due to missing libgmp when installing nokogiri gem on ruby:2.5-slim

You need to apk add --no-cache gmp-dev on your Dockerfile so Nokogiri gem can install native extensions.

Dockerfile で apk add --no-cache gmp-dev してねということです。

追加した結果

Successfully built 32378f90ff55
Successfully tagged app:latest

無事 build できました :tada: :tada:
apk add --no-cache gmp-dev してねというオチで、2, 3日すれば改善されそうですが、今、この瞬間に困っている人の役にたてば!!

このおかげで私はまだ仕事が終わっていない :scream: :scream: :scream:

8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6