如何在Docker容器中通过git安装gem?

时间:2018-01-10 13:57:34

标签: ruby-on-rails docker bundler

我尝试在docker上开发rails app。

docker-compose build成功,但错误发生在docker-compose up

在Gemfile中,我使用带有github的rails,如下所示。 gem 'rails', github: 'rails/rails'

这会导致docker中的错误 - 像这样构成

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

当我像下面编辑Gemfile时,没有发生错误。

gem 'rails'

从错误消息中我发现通过git安装一些gems在容器中失败了。 也许这会导致这个错误。

有没有办法通过容器中的git安装gems?

Dockerfile和docker-compose.yml是here

1 个答案:

答案 0 :(得分:1)

date Week Total '2018-01-10' '00', '104072' '2018-01-10', '48', '2' '2018-01-10', '00', '61' '2018-01-10', '48', '3' 中,更改:

docker-compose.yml

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

这样它就可以在Gemfile的上下文中运行command: bundle exec rails s -p 3000 -b '0.0.0.0'