LoginSignup
2
0

More than 3 years have passed since last update.

Dockerコンテナ上でのbundle installコマンドがcode: 15でエラー終了する時はBUNDLE_PATHの設定を確認する

Last updated at Posted at 2020-08-18

事象

Docker Imageをクリアした日からCIがエラー終了するようになった

bundle install --cleanが失敗するようになってしまった。

Bundle complete! 62 Gemfile dependencies, 187 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Cleaning all the gems on your system is dangerous! If you're sure you want to
remove every system gem not in this bundle, run `bundle clean --force`.
Service 'xxxx' failed to build: The command '/bin/sh -c bundle install --clean' returned a non-zero code: 15

一度Bundle complete!と表示されるのだが、その後Cleaning all the gems on your system is dangerous!としてcode: 15を返してエラー終了してしまっている。


問題となったコンテナのDockerfile

FROM ruby:2.6.5
ENV RUBYOPT -EUTF-8
ENV LANG C.UTF-8
RUN gem install rails -v 6.0.2
# 以下略

原因

RubyのDocker Imageに入った下記の変更により、BUNDLE_PATHが自動で設定されなくなっていた。
Stop setting `BUNDLE_PATH` by deivid-rodriguez · Pull Request #306 · docker-library/ruby

Dockerfile上ではBUNDLE_PATHを指定していなかったため、Imageでの設定が削除されたことでBUNDLE_PATHの指定が空になってしまい、対象がグローバルになってしまった。
だから以下のようなメッセージが表示されたと考えられる。

Cleaning all the gems on your system is dangerous! If you're sure you want to
remove every system gem not in this bundle, run `bundle clean --force`.

しばらくはキャッシュで古いイメージを使っていたため問題が発生しなかったが、キャッシュをクリアしてImageを再取得したことで問題が発生した。

対応

ENV BUNDLE_PATH=$GEM_HOMEをDockerfileに追加することで解消した(上記PRで削除された箇所を、自前のDockerfileに記載する形)。
(最初はdocker-composeファイルのenvironmentに追加したのだがエラーが解消されませんでした。急いでいたので詳しく検証はできていないですが…)

参考

Newest version breaks build - 'Cleaning all the gems on your system is dangerous!' · Issue #3271 · rubygems/rubygems

2
0
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
2
0