Search code examples
ruby-on-railsdockerruby-on-rails-5bundlebundler

Why is "bundle install" returning an error when building my docker repository?


I'm learning how to build a rails application using docker, and each time I attempt to run $ docker-compose build web I get the following error:

You must use Bundler 2 or greater with this lockfile.
ERROR: Service 'web' failed to build: The command '/bin/sh -c bundle install' returned a non-zero code: 20

This is my Dockerfile:

FROM ruby:2.5.1

ENV APP_HOME /usr/src/app
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev

# Node.js
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - \
&& apt-get install -y nodejs

RUN apt-get update && apt-get install -y curl apt-transport-https wget && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install -y yarn

# SOURCE CODE

WORKDIR $APP_HOME

COPY . $APP_HOME/
RUN gem install bundler --version 2.0.2 --no-rdoc --no-ri
ADD Gemfile $APP_HOME/
ADD Gemfile.lock $APP_HOME/
RUN bundle install
RUN echo '--color' >> ~/.rspec

This is my docker-compose.yml file

version: '3'
services:
  db:
    image: postgres
  webpacker:
    build: .
    command: bundle exec bin/webpack-dev-server
    volumes:
      - .:/fancyapp
    ports:
      - "8080:8080"
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/fancyapp
    ports:
      - "3000:3000"
    depends_on:
      - db
      - webpacker

I'm a complete noob with docker and I honestly can't see what's wrong here. I'm basing my implementation on this tutorial


Solution

  • Run the command gem list bundler, I guess your bundler version is less than version 2.

    If so, run gem install bundler -v 2.0.2 to install the latest one.

    You can run gem install --default bundler -v 2.0.2 to make it the default version to be used.