DEV Community

tanakaworld
tanakaworld

Posted on

How to use bundler 2.x with Docker

You would get an error if there is bundler's version difference between BUNDLED WITH in Gemfile.lock and the installed bundler.

https://dev.to/tanakaworld/how-to-resolve-you-must-use-bundler-2-or-greater-with-this-lockfile-2pf7

You can resolve the issue by followings.

  1. Update the gem in image gem update --system
  2. Install any version bundler gem install bundler -v <version>

Example:

FROM ruby:2.6.2

ENV APP_HOME /app
WORKDIR $APP_HOME

COPY Gemfile $APP_HOME/Gemfile
COPY Gemfile.lock $APP_HOME/Gemfile.lock

ENV BUNDLER_VERSION 2.1.0
RUN gem update --system \
    && gem install bundler -v $BUNDLER_VERSION \
    && bundle install -j 4

COPY . $APP_HOME

Top comments (1)

Collapse
 
andresgutgon profile image
Andrés

It works. I just had to change the Gemfile.lock COPY command

When running a fresh project Gemfile.lock is not generated to the way to copy in Docker a non-existing file is with .*


COPY Gemfile.* $APP_HOME/Gemfile.*