Could not find gem rails

17,808

Solution 1

Try to update the version of your RubyGems:

gem update --system

Then change the line in Gemfile to:

gem 'rails', '~> 5.1.5'

Now run bundler to install the gems:

bundle install

Solution 2

Add below lines in your Dockerfile

RUN gem install rails

ruby:2.5-slim this docker image doesn't contain rails. It only contains ruby. You can't install rails using Gemfile. You have to install rails before bundling your gemfile.

Share:
17,808
gbaz
Author by

gbaz

Updated on June 30, 2022

Comments

  • gbaz
    gbaz almost 2 years

    I am trying to build a docker container but getting the following error message:

    Step 8/12 : RUN bundle binstubs bundler --force
     ---> Running in ed94b127974b
    Could not find gem 'rails (>= 5.1.5, ~> 5.1)' in any of the gem sources listed
    in your Gemfile.
    ERROR: Service 'dockerzon' failed to build: The command '/bin/sh -c bundle binstubs bundler --force' returned a non-zero code: 7
    

    I have tried with different versions of rails in my Gemfile with no success! This is what I have in my Gemfile:

    source 'https://rubygems.org'
    
    
    # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
    # gem 'rails', '4.2.6'
    # gem 'rails', '>= 5.1.5'
    gem 'rails', '~> 5.1', '>= 5.1.5'
    # Use sqlite3 as the database for Active Record
    # gem 'sqlite3'
    # Use SCSS for stylesheets
    gem 'sass-rails', '~> 5.0.7'
    # Use Uglifier as compressor for JavaScript assets
    gem 'uglifier', '>= 4.1.6'
    # Use CoffeeScript for .coffee assets and views
    gem 'coffee-rails', '~> 4.2.2'
    # See https://github.com/rails/execjs#readme for more supported runtimes
    # gem 'therubyracer', platforms: :ruby
    
    # Use jquery as the JavaScript library
    gem 'jquery-rails'
    # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
    gem 'turbolinks'
    # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
    gem 'jbuilder', '~> 2.7'
    # bundle exec rake doc:rails generates the API under doc/api.
    gem 'sdoc', '~> 1.0.0', group: :doc
    
    # Use ActiveModel has_secure_password
    # gem 'bcrypt', '~> 3.1.7'
    
    # Use Unicorn as the app server
    # gem 'unicorn'
    
    # Use Capistrano for deployment
    # gem 'capistrano-rails', group: :development
    
    group :development, :test do
      # Call 'byebug' anywhere in the code to stop execution and get a debugger console
      gem 'byebug'
    end
    
    group :development do
      # Access an IRB console on exception pages or by using <%= console %> in views
      gem 'web-console', '~> 3.5.1'
    
      # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
      gem 'spring'
    end
    
    gem 'pg', '~> 1.0.0'
    gem 'redis-rails', '~> 5.0.2'
    gem 'sidekiq', '~> 5.1.1'
    gem 'puma', '~> 3.11.2'
    gem 'rack-timeout', '~> 0.4.2'
    

    and this is my Dockerfile:

    # Use the barebones version of Ruby 2.5
    FROM ruby:2.5-slim
    
    # Optionally set a maintainer name to let people know who made this image.
    
    # Install dependencies:
    # - build-essential: To ensure certain gems can be compiled
    # - nodejs: Compile assets
    # - libpq-dev: Communicate with postgres through the postgres gem
    RUN apt-get update && apt-get install -qq -y --no-install-recommends \
          build-essential nodejs libpq-dev
    
    # Set an environment variable to store where the app is installed to inside
    # of the Docker image. The name matches the project name out of convention only.
    ENV INSTALL_PATH /dockerzon
    RUN mkdir -p $INSTALL_PATH
    
    # This sets the context of where commands will be ran in and is documented
    # on Docker's website extensively.
    WORKDIR $INSTALL_PATH
    
    # Ensure gems are cached and only get updated when they change. This will
    # drastically increase build times when your gems do not change.
    COPY Gemfile Gemfile
    
    # We want binstubs to be available so we can directly call sidekiq and
    # potentially other binaries as command overrides without depending on
    # bundle exec.
    # RUN bundle install --binstubs
    RUN bundle binstubs bundler --force
    
    # Copy in the application code from your work station at the current directory
    # over to the working directory.
    COPY . .
    
    # Provide a dummy DATABASE_URL to Rails so it can pre-compile assets.
    RUN bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:[email protected]/dbname SECRET_TOKEN=dummytoken assets:precompile
    
    # Ensure the static assets are exposed through a volume so that nginx can read
    # in these values later.
    VOLUME ["$INSTALL_PATH/public"]
    
    # The default command that gets ran will be to start the Puma server.
    CMD bundle exec puma -C config/puma.rb
    
  • gbaz
    gbaz about 6 years
    Thanks for that @Atish. Now I am getting the error with the next gem in the file! Could not find gem 'sass-rails (~> 5.0.7)' in any of the gem sources listed in your Gemfile. ERROR: Service 'dockerzon' failed to build: The command '/bin/sh -c bundle binstubs bundler --force' returned a non-zero code: 7
  • Admin
    Admin about 6 years
    Remove '~> 5.0.7' from saas-rails and '~> 4.2.2' from coffee-rails in Gemfile. Let gem file take the installed version of these gems. There must be rails 5.1 version installed, which is the latest one, thats why saas-rails 5.0 version is giving not found error.
  • gbaz
    gbaz about 6 years
    that didn't work Step 9/13 : RUN bundle binstubs bundler --force ---> Running in bd13ecd38b04 Could not find gem 'sass-rails' in any of the gem sources listed in your Gemfile. ERROR: Service 'dockerzon' failed to build: The command '/bin/sh -c bundle binstubs bundler --force' returned a non-zero code: 7. The gems install from the Gemfile if I run "bundle install" but not if I run bundle binstubs bundler --force which I am trying to use
  • gbaz
    gbaz about 6 years
    Thanks @Kandy. This works fine if I run "bundle install" like you suggested but not if I run "bundle binstubs bundler --force" which I am trying to use
  • Gtx
    Gtx about 3 years
    Still helpful in 2021. Thanks :)