【问题标题】:How to install gems via git in Docker container?如何在 Docker 容器中通过 git 安装 gem?
【发布时间】:2018-01-10 13:57:34
【问题描述】:

我尝试在 docker 上开发 rails 应用程序。

docker-compose build成功,但是docker-compose up出现错误。

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

这会导致 docker-compose up 这样的错误

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 安装一些 gem 在容器中失败。 也许这会导致这个错误。

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

Dockerfile 和 docker-compose.yml 是 here

【问题讨论】:

  • 你可能需要在 Dockerfile 中安装 git

标签: ruby-on-rails docker bundler


【解决方案1】:

docker-compose.yml,更改:

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

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

这样它就可以在 Gemfile 的上下文中运行 rails

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-13
    • 2017-11-11
    • 2021-09-08
    • 1970-01-01
    • 1970-01-01
    • 2022-07-13
    • 1970-01-01
    相关资源
    最近更新 更多