Docker Ruby on Rails container cannot load such file -- /..bundler-2.2.30/exe/bundle (Load Error)

Viewed 228

i'm trying to containerize my RoR application and following this guide i managed to run docker-compose build without problems. I need to create a container for application itself and pgsql database. Once the docker-compose up part arrives the database runs perfectly but the application throws this problem:

/usr/local/bundle/bin/bundle:23:in load': cannot load such file --/usr/local/bundle/gems/bundler-2.2.30/exe/bundle (LoadError) app_1| from /usr/local/bundle/bin/bundle:23:in '

I tried to change ruby version, to install again everything, to run it with different bundler -v, but always getting the same problem... following my environment.

My Ruby version is: 2.6.8p205.

My bundler version is: 2.2.3.

Here's my Gemfile:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.8'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.5'
# Use postgresql as the database for Active Record
gem 'pg', '~> 1.1'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sassc', '~> 2.1'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 4.1.0'
# Display performance information such as SQL time and flame graphs for each request in your browser.
# Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
gem 'rack-mini-profiler', '~> 2.0'
gem 'listen', '~> 3.3'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end

group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 3.26'
gem 'selenium-webdriver', '>= 4.0.0.rc1'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'devise'
gem 'bootstrap', '~> 5.1.3'
gem 'haml-rails'
gem 'devise-encryptable'
gem 'uuidtools'
gem 'administrate'
gem 'paypal-checkout-sdk'
gem 'pay', '~> 3.0'
gem 'stripe', '>= 5.0', '< 6.0'
gem 'braintree', '>= 4.6', '< 5.0'
gem 'paddle_pay', '~> 0.2'
gem 'receipts', '~> 2.0'
gem 'letter_opener', group: :development
gem 'dotenv'
gem "nokogiri", ">= 1.6.7.rc"

Here's my Dockerfile:

FROM ruby:2.6.8-alpine
ENV BUNDLER_VERSION=2.2.3
RUN apk add --update --no-cache \
  binutils-gold \
  build-base \
  curl \
  file \
  g++ \
  gcc \
  git \
  less \
  libstdc++ \
  libffi-dev \
  libc-dev \ 
  linux-headers \
  libxml2-dev \
  libxslt-dev \
  libgcrypt-dev \
  make \
  netcat-openbsd \
  nodejs \
  openssl \
  pkgconfig \
  postgresql-dev \
  tzdata \
  yarn 

RUN gem install bundler -v 2.2.30
RUN gem uninstall nokogiri
WORKDIR /app
RUN gem install nokogiri
COPY Gemfile Gemfile.lock ./
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle check || bundle install
COPY package.json yarn.lock ./
RUN yarn install --check-files
COPY . ./ 

ENTRYPOINT ["./entrypoints/docker-entrypoint.sh"]

Here's my docker-entrypoint.sh:

#!/bin/sh
set -e

if [ -f tmp/pids/server.pid ]; then
  rm tmp/pids/server.pid
fi
bundle install
bundle exec rails s -b 0.0.0.0

And here's my docker-compose.yml:

version: '3.4'

services:
  app: 
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      - database
    ports: 
      - "3000:3000"
    volumes:
      - .:/app
      - gem_cache:/usr/local/bundle/gems
      - node_modules:/app/node_modules
    env_file: .env
    environment:
      RAILS_ENV: development

  database:
    image: postgres:12.1
    volumes:
      - db_data:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql

volumes:
  gem_cache:
  db_data:
  node_modules:

Thanks to everyone that could help me...

1 Answers

Here are my 2 working config for rails, try using this for gem install part:

RUN gem install bundler:2.2.30 && bundle config set deployment without 'development test' with 'runtime' && bundle install

or

RUN gem install bundler --no-document
RUN bundle install --no-binstubs --jobs $(nproc) --retry 3 --without development test

without ENV BUNDLER_VERSION=2.2.3 env

EDIT: i forgot to mention, alpine gave me problems with a non api-only app, so i used standard docker image.

Related