rails docker app bundle rake aborted - ruby-on-rails

I'm trying to create a Rails app using docker and am getting an error during my initial docker build. I've been following various tutorials to try to get this to work, but am not having any luck.
My error:
Step 10/12 : RUN bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:pass#127.0.0.1/neo SECRET_TOKEN=foobar assets:precompile
---> Running in d3d282e3eb8b
/usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:51: warning: constant ::Fixnum is deprecated
/usr/local/bundle/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:52: warning: constant ::Bignum is deprecated
rake aborted!
NoMethodError: undefined method `split' for nil:NilClass
/app/config/application.rb:57:in `<class:Application>'
/app/config/application.rb:10:in `<module:NeoDocker>'
/app/config/application.rb:9:in `<top (required)>'
/app/Rakefile:5:in `require_relative'
/app/Rakefile:5:in `<top (required)>'
/usr/local/bundle/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
(See full trace by running task with --trace)
The command '/bin/sh -c bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:pass#127.0.0.1/neo SECRET_TOKEN=foobar assets:precompile' returned a non-zero code: 1
Dockerfile:
FROM ruby:2.4.1
RUN apt-get update && apt-get install -qq -y --no-install-recommends \
build-essential nodejs libpq-dev
ENV INSTALL_PATH /app
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY Gemfile Gemfile.lock ./
RUN bundle install --binstubs
COPY . .
RUN bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:pass#127.0.0.1/neo SECRET_TOKEN=foobar assets:precompile
VOLUME ["$INSTALL_PATH/public"]
CMD puma -C config/puma.rb
My Gemfile is pretty much the default for Rails 5 now:
source 'https://rubygems.org'
gem 'rails', '~> 5.0.1'
gem 'puma', '~> 3.0'
gem 'rack-timeout', '~> 0.4'
gem 'jbuilder', '~> 2.5'
gem 'pg', '~> 0.18'
gem 'redis-rails', '~> 5.0.0.pre'
gem 'sidekiq', '~> 4.2'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'jquery-rails'
gem 'turbolinks', '~> 5'
gem 'bootstrap-sass', '~> 3.3'
gem 'font-awesome-rails', '~> 4.7'
group :development, :test do
gem 'byebug', platform: :mri
end
group :development do
gem 'rack-mini-profiler', '~> 0.10'
gem 'web-console', '~> 3.3.0'
gem 'listen', '~> 3.0.5'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
What's wrong here?

I think you solve your problem but maybe the answer help someone
The warning you can try solving updating Rails in your Gemfile, changing:
gem 'rails', '~> 5.0.1'
by
gem 'rails', '~> 5.0.2'
and then execute bundle update rails (I don't know if in Docker is necesary)
Also maybe you can have an error in your /app/config/application.rb file in line 57

Here is your solution.
https://github.com/giapnhdev/rails-base
It includes some awesome gems for your project like:
devise, seed_fu, shrine,...

Related

Bundle install fails only in CircleCI(mysql2)

Want to achieve
Thank you for browsing.
I got the following error when using "bundle install" to build with CircleCI.
In my environment, I can install the bundle without any problems.
I hope you can tell me how to solve this problem.
error
To see why this extension failed to compile, please check the mkmf.log which can
be found here:
/home/circleci/myapp/web/vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0-static/mysql2-0.5.2/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in
/home/circleci/myapp/web/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.2 for
inspection.
Results logged to
/home/circleci/myapp/web/vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0-static/mysql2-0.5.2/gem_make.out
An error occurred while installing mysql2 (0.5.2), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'`
succeeds before bundling.
In Gemfile:
mysql2
Exited with code exit status 5
CircleCI received exit code 5
Codes
.circleci/config.yml
version: 2.1
orbs:
ruby: circleci/ruby#1.1.2
jobs:
build:
docker:
- image: cimg/ruby:2.6.5
working_directory: ~/myapp/web
steps:
- checkout:
path: ~/myapp
- ruby/install-deps
workflows:
version: 2
build_and_test:
jobs:
- build
Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.5'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.7'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.4.4'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.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'
# jQuery
gem "jquery-rails"
gem 'rails-i18n', '~> 6'
gem "enum_help"
gem "config"
gem 'faraday'
gem 'acts_as_paranoid', '~> 0.6.0'
gem 'http-cookie'
gem 'kaminari'
gem 'devise'
gem 'devise_token_auth'
gem 'devise-security'
gem 'devise-two-factor', '~> 3.1'
# AWS
gem 'aws-sdk'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
gem 'composite_primary_keys'
# Antivirus
gem 'clamav-client', require: 'clamav/client'
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', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# 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]
I tried
Mention to run gem install mysql2 -v before ruby/install-deps
- run:
name: Install mysql2
command: gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'
- ruby/install-deps
↓
build
↓
Another error occurred.
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/home/circleci/.rubygems/extensions/x86_64-linux/2.6.0-static/mysql2-0.5.2/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /home/circleci/.rubygems/gems/mysql2-0.5.2 for inspection.
Results logged to /home/circleci/.rubygems/extensions/x86_64-linux/2.6.0-static/mysql2-0.5.2/gem_make.out
Exited with code exit status 1
CircleCI received exit code 1
I modified the config.yml as follows and was able to build
steps:
- checkout:
path: ~/myapp
- run:
name: default mysql client install
command: |
sudo apt update
sudo apt-get install default-mysql-client
sudo apt-get install libmysqlclient-dev
- run:
name: bundle Install
command: bundle install --path vendor/bundle

Bundler::GemNotFound: Could not find rake-12.3.2 in any of the sources

Error when running rails docker container with volumes
bundler: failed to load command: rails (/usr/local/bundle/bin/rails)
Bundler::GemNotFound: Could not find rake-12.3.2 in any of the sources
I am able to run my rails docker container without volume.
But when i attach volume as such:
docker run --name rails-chat-tutorial-web \
-e DATABASE_HOST=172.17.0.1 \
-e DATABASE_PORT=5432 \
-e DATABASE_USERNAME=postgres \
-e DATABASE_PASSWORD=postgres \
-e REDIS_URL=redis://172.17.0.1:6379/1 \
-p 3000:3000 \
-v $(pwd):/application rails-chat-tutorial
I will get this error output:
bundler: failed to load command: rails (/usr/local/bundle/bin/rails)
Bundler::GemNotFound: Could not find rake-12.3.2 in any of the sources
/usr/local/bundle/gems/bundler-2.0.1/lib/bundler/spec_set.rb:87:in `block in materialize'
/usr/local/bundle/gems/bundler-2.0.1/lib/bundler/spec_set.rb:81:in `map!'
/usr/local/bundle/gems/bundler-2.0.1/lib/bundler/spec_set.rb:81:in `materialize'
/usr/local/bundle/gems/bundler-2.0.1/lib/bundler/definition.rb:170:in `specs'
/usr/local/bundle/gems/bundler-2.0.1/lib/bundler/definition.rb:237:in `specs_for'
/usr/local/bundle/gems/bundler-2.0.1/lib/bundler/definition.rb:226:in `requested_specs'
/usr/local/bundle/gems/bundler-2.0.1/lib/bundler/runtime.rb:108:in `block in definition_method'
/usr/local/bundle/gems/bundler-2.0.1/lib/bundler/runtime.rb:20:in `setup'
/usr/local/bundle/gems/bundler-2.0.1/lib/bundler.rb:107:in `setup'
/usr/local/bundle/gems/bundler-2.0.1/lib/bundler/setup.rb:20:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
I have tried including these lines in my Dockerfile but still get the error:
RUN gem install rake -v '12.3.2'
RUN bundle install --binstubs
RUN bundle install --path vendor/bundle
RUN bundle install --local
RUN bun
dle install --local --path=vendor/cache
This is my Dockerfile:
FROM ruby:2.5.0-stretch
COPY ./Gemfile ./application/
COPY ./Gemfile.lock ./application/
WORKDIR /application
ENV BUNDLER_VERSION 2.0.1
RUN gem install bundler -v '2.0.1'
RUN bundle install --deployment --without development test
RUN apt-get update -qq && apt-get install -y build-essential
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install -y nodejs
RUN bundle install --local --path=vendor/cache
RUN npm install yarn -g
COPY . .
ENV RAILS_ENV production
ENV SECRET_KEY_BASE production_test_key rails c
RUN bundle exec rake assets:precompile
EXPOSE 3000
CMD bundle exec rails server
Content of Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', 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', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end
group :production do
gem 'pg'
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', '~> 4.3.1'
gem 'jquery-rails'
gem 'simple_form'
gem 'redis'
gem 'httparty', '~> 0.17.0'
gem 'rake', '12.3.2'
If I run the rails container with shell and gem list, i get 'rake (12.3.2, 12.3.0)'
I have been on this for the past 2 days but no progress.
Thank you in advance for those who are able to provide some guidance.
When you add a docker run -v $(pwd):/application option, it hides everything in the /application directory in the image and replaces it with the content from your host system. That in particular includes the /application/vendor directory: any bundle commands in your Dockerfile are completely ignored, and your host system's ./vendor directory gets used instead.
There's not really a good answer to this, if you must have live editing and reloading in your deployed container. The Node ecosystem is similar (third-party libraries are in ./node_modules) and most similar questions are about Node rather than Ruby. Add a volume to Docker, but exclude a sub-folder suggests adding an anonymous volume for ./vendor; the first time only that you run your application it will get populated from the image, but if you later change your Gemfile it won't get updated and replicating this setup is unnecessarily complicated in cluster environments like Kubernetes.
If you want to try the anonymous-volume path, that could look like
docker run --name rails-chat-tutorial-web ... \
-v $PWD:/application -v /application/vendor \
rails-chat-tutorial
$EDITOR Gemfile
bundle install
docker stop rails-chat-tutorial-web
docker rm -v rails-chat-tutorial-web
docker run ...
(docker rm -v will delete the anonymous volume, and it will get recreated on the next docker run with updated contents. You've told Docker that directory contains important non-code data that must be preserved across runs.)
The sequence that's worked well for me is to develop my application in total ignorance of Docker: develop it locally, run it, write good rspec tests, and generally believe it works. Only then do I docker build and docker run an image, without bind-mounting my source code into it. If it breaks then I reproduce the issue on my local development environment, write a test for it, and fix it, then repeat the docker build; docker run sequence.

Docker Compose Could not locate Gemfile or .bundle/ directory

When I run docker-compose up -d I get the following error:
web_1 | Could not locate Gemfile or .bundle/ directory
However the image is being created. I want to have a Rails application, and for the Docker files to live outside the rails application. I have the following Dockerfile
FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
WORKDIR /app
COPY ./app/Gemfile Gemfile
# Install Gems
RUN bundle install
ADD . /app
In the docker-compose.yml file I have the Following configuration:
version: '3'
services:
db:
image: postgres:9.6.1 # To Edit - Default is postgresql.
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/app
ports:
- "3000:3000"
depends_on:
- db
And for the Gemfile I have the following code:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.0'
# Use postgresql as the database for Active Record
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# 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.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', 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', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15', '< 4.0'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
I'm not sure if it has something to do with the Rails or Ruby version. I also see that the Gemfile is there once I go into the container and run ls so is not that theres no Gemfile.
root#ab38d643df47:/app# ls
Dockerfile Gemfile Gemfile.lock README.md app docker-compose.yml
try this:
FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
WORKDIR app
COPY Gemfile Gemfile
# Install Gems
RUN bundle install
ADD . app

Rails can't find rake gem for docker app

I have a Rails application running in docker. I have two images which are connected. I can't run server of one of them and it works fine, but I cannot run another one and none of simple commands doesn't work too. It fails telling me Could not find rake-12.3.1 in any of the sources.
There is already existing solution
None of the solutions from link above doesn't work.
Error looks like this
bundler: failed to load command: puma (/usr/local/bundle/bin/puma)
Bundler::GemNotFound: Could not find rake-12.3.1 in any of the sources
Here is my Gemfile:
source 'https://rubygems.org'
gem 'rails', '~> 4.2'
gem 'rails-i18n'
gem 'responders', '~> 2.0'
gem 'puma'
gem 'mysql2', '~> 0.3.21'
gem 'redis-rails'
gem 'json'
gem 'jbuilder'
gem 'omniauth', '~> 1.8.1'
gem 'omniauth-auth0', '~> 2.0.0'
gem 'omniauth-google-oauth2', '~> 0.5.2'
gem 'omniauth-barong', '~> 0.1.2'
gem 'figaro'
gem 'hashie', '~> 3.0'
gem 'aasm', '~> 4.12'
gem 'bunny', '~> 2.9.0'
gem 'cancancan'
gem 'enumerize'
gem 'datagrid'
gem 'kaminari'
gem 'paranoid2'
gem 'active_hash'
gem 'http_accept_language'
gem 'paper_trail', '~> 3.0.1'
gem 'rails-observers'
gem 'country_select', '~> 2.1.0'
gem 'gon', '~> 5.2.0'
gem 'pusher'
gem 'eventmachine', '~> 1.0.4'
gem 'em-websocket', '~> 0.5.1'
gem 'simple_form', '~> 3.1.0'
gem 'slim-rails'
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier', '~> 4.1'
gem 'jquery-rails'
gem 'angularjs-rails', '~> 1.3.15'
gem 'bootstrap-sass', '~> 3.2.0.2'
gem 'font-awesome-sass'
gem 'bourbon'
gem 'momentjs-rails'
gem 'eco'
gem 'browser', '~> 0.8.0'
gem 'rbtree'
gem 'liability-proof', '0.0.9'
gem 'grape', '~> 1.0.1'
gem 'grape-entity', '~> 0.5.2'
gem 'grape-swagger', '~> 0.27.3'
gem 'grape-swagger-ui', '~> 2.2.8'
gem 'rack-attack', '~> 4.3.1'
gem 'easy_table'
gem 'faraday', '~> 0.12'
gem 'jwt', '~> 1.5'
gem 'email_validator', '~> 1.6'
gem 'clipboard-rails', '~> 1.7'
gem 'god', '~> 0.13.7', require: false
gem 'mini_racer', '~> 0.1', require: false
gem 'arel-is-blank', '~> 1.0'
gem 'sentry-raven', '~> 2.7', require: false
gem 'memoist', '~> 0.16'
gem 'method-not-implemented', '~> 1.0'
gem 'passgen', '~> 1.0'
gem 'validates_lengths_from_database', '~> 0.7.0'
group :development, :test do
gem 'factory_bot_rails'
gem 'faker', '~> 1.4.3'
gem 'binding_of_caller'
gem 'quiet_assets'
gem 'timecop'
gem 'rspec-rails', '~> 3.7'
gem 'pry-byebug'
end
group :development do
gem 'annotate', '~> 2.7'
end
group :test do
gem 'database_cleaner'
gem 'mocha', require: false
gem 'capybara', '~> 2.17'
gem 'selenium-webdriver', '~> 3.8'
gem 'chromedriver-helper', '~> 1.1'
gem 'rack_session_access', '~> 0.1'
gem 'webmock', '~> 3.3'
end
Here is Dockerfile
FROM ruby:2.5.0
MAINTAINER lbellet#heliostech.fr
ARG RAILS_ENV=production
ENV RAILS_ENV ${RAILS_ENV}
ENV APP_HOME=/home/app
RUN groupadd -r app --gid=1000
RUN useradd -r -m -g app -d /home/app --uid=1000 app
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/source$
&& apt-get update \
&& apt-get install -y \
default-libmysqlclient-dev \
imagemagick \
gsfonts \
chromedriver \
nodejs \
yarn
WORKDIR $APP_HOME
COPY Gemfile Gemfile.lock $APP_HOME/
# Install dependencies
RUN mkdir -p /opt/vendor/bundle && chown -R app:app /opt/vendor
RUN su app -s /bin/bash -c "bundle install --path /opt/vendor/bundle"
# Copy the main application.
COPY . $APP_HOME
RUN chown -R app:app /home/app
USER app
RUN ./bin/init_config \
&& chmod +x ./bin/logger \
&& bundle exec rake tmp:create yarn:install assets:precompile
# Expose port 8080 to the Docker host, so we can access it
# from the outside.
EXPOSE 8080
ENTRYPOINT ["bundle", "exec"]
# The main command to run when the container starts. Also
# tell the Rails dev server to bind to all interfaces by
# default.
CMD ["puma", "--config", "config/puma.rb"]
I tried to reinstall docker, change ruby version, delete Gemfile.lock, but nothing seems to work. How can I resolve that?
Had a similar situation, this worked for me:
bundle install --binstubs
I believe that you need to update your rbenv-bundler from homebrew.
Try:
brew upgrade rbenv-bundler
Then, try installing the gem.
gem install rake -v 12.3.1

Could not find gem rails

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:pass#127.0.0.1/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
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
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.

Resources