DEV Community

tanakaworld
tanakaworld

Posted on

3 2

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

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay