If the bundle install command on the Docker container ends with an error at code: 15, check the BUNDLE_PATH setting

Event

CI now ends with an error from the day you clear Docker Image

bundle install --clean now fails.

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

It says Bundle complete! Once, but after that it returns code: 15 asCleaning all the gems on your system is dangerous!And ends with an error.


Dockerfile for the container in question

FROM ruby:2.6.5
ENV RUBYOPT -EUTF-8
ENV LANG C.UTF-8
RUN gem install rails -v 6.0.2
#The following is omitted

Cause

BUNDLE_PATH was not set automatically due to the following changes in Ruby's Docker Image. Stop setting `BUNDLE_PATH` by deivid-rodriguez · Pull Request #306 · docker-library/ruby

Since BUNDLE_PATH was not specified on the Dockerfile, the specification of BUNDLE_PATH became empty due to the deletion of the setting in Image, and the target became global. Therefore, it is probable that the following message was displayed.

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`.

I hadn't had a problem because I was using an old image in the cache for a while, but I had a problem by clearing the cache and reacquiring the Image.

Correspondence

This was solved by adding ʻENV BUNDLE_PATH = $ GEM_HOME to the Dockerfile (the part deleted by the above PR is described in your own Dockerfile). (At first I added it to ʻenvironment of the docker-compose file, but the error was not resolved. I was in a hurry so I have not been able to verify it in detail ...)

reference

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

Recommended Posts

If the bundle install command on the Docker container ends with an error at code: 15, check the BUNDLE_PATH setting
Workspace setting location when connecting remotely with VS Code and working on a Docker container
After setting database to mysql, bundle install causes an error
Time is wrong with the application launched on the Docker container
I don't see an error in Rails bundle install ... the solution
What to do if you get an error with bundle install by entering gem'bcrypt' in your Gemfile
Add gem'rails-i18n','~> 6.0.0' and what to do if bundle install gives an error
I get an error with bundle install and puma cannot be installed.
What to do if an error occurs when nokogiri enters when bundle install
[Docker] How to build when the source code is bind-mounted on the container
Copying the repository and getting a mysql2 error on the first bundle install