Search code examples
ruby-on-railsdockerbundler

How to install gems via git in Docker container?


I try to develop rails app on docker.

docker-compose build is succeed, but the error occured in docker-compose up.

In Gemfile, I use rails with github like below. gem 'rails', github: 'rails/rails'

This cause error in docker-compose up like this

web_1  | /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/dependency.rb:310:in `to_specs': Could not find 'activesupport' (>= 4.2) among 110 total gem(s) (Gem::MissingSpecError)
web_1  | Checked in 'GEM_PATH=/usr/local/bundle:/root/.gem/ruby/2.5.0:/usr/local/lib/ruby/gems/2.5.0', execute `gem env` for more information
web_1  |    from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/specification.rb:1464:in `block in activate_dependencies'
web_1  |    from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/specification.rb:1453:in `each'
web_1  |    from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/specification.rb:1453:in `activate_dependencies'
web_1  |    from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/specification.rb:1435:in `activate'
web_1  |    from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_gem.rb:68:in `block in gem'
web_1  |    from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_gem.rb:67:in `synchronize'
web_1  |    from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_gem.rb:67:in `gem'
web_1  |    from /hateblocker/bin/spring:14:in `<top (required)>'
web_1  |    from bin/rails:3:in `load'
web_1  |    from bin/rails:3:in `<main>'
hateblocker_web_1 exited with code 1

When I edited Gemfile like below, no error occured.

gem 'rails'

From error message I found that installing some gems via git failed in container. Maybe this cause this error.

Is there any way to install gems via git in container?

Dockerfile and docker-compose.yml is here.


Solution

  • In docker-compose.yml, change:

    command: bin/rails s -p 3000 -b '0.0.0.0'
    

    to

    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    

    So that it can run rails in context of Gemfile.