4

I am trying to install bundler version 2.1 in a docker image that is built from ruby:2.4.1. My Docker file looks the following way:

FROM ruby:2.4.1

RUN \
  gem update --system --quiet && \
  gem install  bundler -v '~> 2.1'

# Other commands

But when I try to run bundle install it fails with

You must use Bundler 2 or greater with this lockfile.

When I run inside a container gem info bundler it outputs:

bundler (2.1.2, 1.15.4)
    Authors: André Arko, Samuel Giddins, Colby Swandale, Hiroshi
    Shibata, David Rodríguez, Grey Baker, Stephanie Morillo, Chris
    Morris, James Wen, Tim Moore, André Medeiros, Jessica Lynn Suttles,
    Terence Lee, Carl Lerche, Yehuda Katz
    Homepage: https://bundler.io
    License: MIT
    Installed at (2.1.2): /usr/local/bundle
                 (1.15.4): /usr/local/lib/ruby/gems/2.4.0

I tried the following fixes:

# Set bundler 2.1.2 as default
bundler config default 2.1.2

# Update bundler
gem update bundler

But they didn't work. The system continues to use bundler v1.15.4

How can I make bundler v2.1.2 as default inside a ruby docker image?

Hirurg103
  • 4,783
  • 2
  • 34
  • 50
  • Possible duplicate [Bundler: You must use Bundler 2 or greater with this lockfile](https://stackoverflow.com/questions/53231667/bundler-you-must-use-bundler-2-or-greater-with-this-lockfile) – Tamer Shlash Dec 23 '19 at 12:31
  • What's the version number in your `Gemfile.lock`; is it exactly 2.1.2? Can you edit your question to include the relevant `COPY` and `RUN` Dockerfile instructions that reproduce this? – David Maze Dec 23 '19 at 12:32
  • @DavidMaze Gemfile.lock has `BUNDLED WITH 2.1.1`. I guess that any bundler version greater than `2.0.0` would be OK. I use docker image from the question to run builds with Gitlab CI, and there are no RUN and COPY commands that reproduce the issue. These commands are located in `.gitlab-ci.yml`. I will update my question, thank you – Hirurg103 Dec 23 '19 at 12:43
  • Bundler 2.1 has [a pretty significant bug](https://github.com/bundler/bundler/issues/7489) that you must have _exactly_ the bundler version named in the `Gemfile.lock` version installed. The symptom isn't quite what you describe here, but semantic-version constraints don't work any more. Does `gem install bundler -v 2.1.1` make a difference? – David Maze Dec 23 '19 at 12:49
  • Can you remove v1.15.4 with gem uninstall? – simonwo Dec 26 '19 at 11:01
  • @simonwo possibly removing the old bundler version will work - I haven't tried it yet. I've already found [solution](https://stackoverflow.com/a/59722212/3676469) that is working for me – Hirurg103 Jan 13 '20 at 18:36
  • @DavidMaze in the issue you mentioned rubygems are complaining that the older bundler version that the previous release was deployed with is missing. At the other hand in this issue bundler is complaining that the new version of bundler is expected – Hirurg103 Jan 13 '20 at 18:59
  • @TamerShlash [the first comment](https://stackoverflow.com/questions/53231667/bundler-you-must-use-bundler-2-or-greater-with-this-lockfile#comment98008635_53231667) to the question you mentioned as a possible duplicate helped me to answer my question. Not sure if my question is a duplicate because I got this error in a Docker container although the OQ relates to Heroku environment – Hirurg103 Jan 13 '20 at 19:07

2 Answers2

6

I was able to switch to bundler version 2.1 in my docker image using the following commands:

# Dockerfile
RUN \
  gem update --system --quiet && \
  gem install  bundler -v '~> 2.1'
ENV BUNDLER_VERSION 2.1
Hirurg103
  • 4,783
  • 2
  • 34
  • 50
-2

For using previous version, try this fix. Looks like issue with Gemfile.lock. Try removing BUNDLED WITH from gemfile.lock.

Remove something like and build again

BUNDLED WITH
   2.1.4
Vivek V C
  • 7
  • 5