Home > OS >  Bundler 2.2.0 and Ruby 2.7.5 on Docker crashing
Bundler 2.2.0 and Ruby 2.7.5 on Docker crashing

Time:05-30

I installed Ruby 2.7.5, and within the Dockerfile, specified bundler (version 2.2.0) to be installed:

RUN gem install bundler -v 2.2.0 --no-document

the output of this is:

INFO[0093] RUN gem install bundler -v 2.2.0 --no-document 
INFO[0093] cmd: /bin/sh                                 
INFO[0093] args: [-c gem install bundler -v 2.2.0 --no-document] 
INFO[0093] Running: [/bin/sh -c gem install bundler -v 2.2.0 --no-document] 
Successfully installed bundler-2.2.0

All seemed to be fine in that install, and bundle works as gems specified in Gemfile are installed. However, when I try to open the console, I see this:

/usr/lib/ruby/2.7.0/rubygems.rb:277:in `find_spec_for_exe': Could not find 'bundler' (2.2.0) required by your /app/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.2.0`

However, it is installed. as you can see from above. Also, when I output the version within the Dockerfile, I see:

Bundler version 2.2.0

It seemed to install fine, however, still see the error above, and it crashes immediately.

Is there something obvious I am doing wrong?

CodePudding user response:

Building a Docker Image with an Updated Bundler Version

You're missing a couple of steps in your Dockerfile build for bundled gems. After you update Bundler, you also need to update your Gemfile.lock and possibly re-run bundle install. There are a lot of options involved, but here's my personal recommendation for your Dockerfile based on your post:

# Note: Don't lock your Bundler version unless you
# have a VERY good reason to do so. Update will
# install or update, as needed.
RUN gem update bundler --no-document \
    && gem clean bundler \
    && bundle update --bundler \
    && bundle install

The key here is that if you don't use bundle update --bundler then the Gemfile.lock will not contain the version of Bundler that you're expecting to call. Recent versions of Bundler will downgrade themselves to the version in the Gemfile.lock if necessary, so this is really the key to the whole thing.

In addition, if you continue to have problems after applying the recipe above, you may need to figure out where Bundler is actually being installed inside your container image. While Bundler (currently) doesn't run from inside your bundle, the required version still needs to be in GEM_HOME, GEM_ROOT, or GEM_PATH in order to be found when you invoke it.

As a final consideration, if you're building your gems locally or modifying your Gemfile.lock and then using an ADD or COPY command to place the Gemfile.lock or any vendored gems into your container image, you need to perform these activities outside of Docker rather than inside the Dockerfile. Based on your original post it doesn't look like you're doing that now, but it's another option to consider as you work on resolving this.

  • Related