You must use Bundler 2 or greater with this lockfile. When running docker-compose up locally

12,470

Solution 1

Adding this line before RUN bundle install to the Dockerfile did the trick for me.

RUN gem install bundler -v 2.0.1

Leaving this here for future reference!

Solution 2

You need to update Rubygems:

RUN gem update --system

Apart of being sure that you have the correct bundler version, run:

RUN gem install bundler -v 2.0.1

Here you can find a deeply explanation.

Solution 3

Ruby image comes with installed bundler. Environment variable BUNDLER_VERSION is set to preinstalled version of bundler by default. Even if you uninstall this version, bundle will check for this environment variable and raise error "You must use Bundler 2 or greater with this lockfile" if there is a v1/v2 mismatch

Ensure that your Gemfile.lock bundled with needed version:

BUNDLED WITH
   2.1.4

If you have another version, you can upgrade your application to the latest installed version of Bundler by running bundle update --bundler https://bundler.io/man/bundle-update.1.html

In Dockerfile override environment variable BUNDLER_VERSION to needed version of bundler and install it:

ENV BUNDLER_VERSION=2.1.4

RUN gem update --system && \
    gem install bundler:2.1.4 && \
    bundle install

Solution 4

in your Gemfile.lock, at the bottom, you may find bundle version:

BUNDLED WITH
2.0.1

Please make sure you bundled it with the correct version that you have

Share:
12,470
queroga_vqz
Author by

queroga_vqz

Updated on June 09, 2022

Comments

  • queroga_vqz
    queroga_vqz almost 2 years

    New to docker, I have been trying to use it with my rails project but haven't been able to start it up.

    Tried changing ruby versions, and searching the web, but most questions involved deploying the app to heroku, which is not my case.

    Docker file:

    FROM ruby:2.4.1
    RUN mkdir /zssn
    WORKDIR /zssn
    COPY Gemfile /zssn/Gemfile
    COPY Gemfile.lock /zssn/Gemfile.lock
    RUN gem install bundler
    RUN bundle --version
    RUN bundle install
    COPY . /zssn
    
    CMD ["rails", "server"]
    

    docker-compose-yml

    version: '3'
    services:
      web:
        build: .
        command: rails s -p 3000 -b '0.0.0.0'
        volumes:
          - .:/zssn
        ports:
          - "3000:3000"
    

    docker build . --no-cache, seems to be working fine when running the bundler command to install it.

     ---> Running in d4650608f428
    Successfully installed bundler-2.0.1
    

    Any ideas?

  • queroga_vqz
    queroga_vqz about 5 years
    thanks for the reply! Tried, but still had no luck.
  • javierojeda
    javierojeda almost 4 years
    This did not work for me... Any suggestion? I locally created the project with bundler 2.1.4 and specified the same version on Dockerfile as well as a gem update --system before.