Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 211
queroga_vqz Avatar asked Apr 29 '19 19:04

queroga_vqz


2 Answers

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
like image 120
artem_russkikh Avatar answered Oct 22 '22 06:10

artem_russkikh


I think you need to either upgrade to a ruby image that comes with bundler 2 (e.g. FROM ruby:2.6.3) or rebundle your Gemfile.lock with the bundler version you want to use. Or at least that's what worked for me.

It did not work to tweak the environment variables as suggested by the Bundler guides.

This github issue makes me think this is expected behavior, but I could be totally wrong.

like image 34
eremite Avatar answered Oct 22 '22 06:10

eremite