【问题标题】:Rails & docker - can't install json gemRails & docker - 无法安装 json gem
【发布时间】:2016-07-07 15:43:45
【问题描述】:

我尝试在 docker 上使用 panamax-ui(一个 RoR 应用程序)。 我在它上面工作了几天(本地和 docker),成功地修改了它等等。

然后我添加了一些新的功能和一些宝石。

我有bundle install 一切。

然后我想重新构建我的 docker (docker build)

但我遇到了这个错误:

Gem::Ext::BuildError: ERROR: 未能构建 gem 原生扩展。

/usr/bin/ruby extconf.rb 创建 Makefile

make "DESTDIR=" clean sh: make: not found

make "DESTDIR=" sh: make: not found

制作失败,退出代码 127

Gem 文件将继续安装在 /usr/lib/ruby/gems/2.1.0/gems/json-1.8.3 用于检查。结果 登录到 /usr/lib/ruby/gems/2.1.0/extensions/x86_64-linux/2.1.0/json-1.8.3/gem_make.out 安装json(1.8.3)时出错,Bundler不能 继续。确保 gem install json -v '1.8.3' 之前成功 捆绑。命令'/bin/sh -c bundle install --without development test' 返回一个非零代码:5

我试图删除 Gemfile.lock 并重新运行 bundle install 然后重建 docker,同样的错误...

这是我的Gemfile

source 'https://rubygems.org'

gem 'rails', '4.1.7'
gem 'puma', '2.8.2'
gem 'sqlite3', '1.3.9'
gem 'faraday_middleware', '0.9.0'
gem 'docker-api', '1.13.0', require: 'docker'
gem 'fleet-api', '1.1.0', require: 'fleet'
gem 'active_model_serializers', '0.9.0'
gem 'octokit', '3.2.0'
gem 'kmts', '2.0.1'
gem 'devise'
gem "devise_ldap_authenticatable"
gem 'json', '1.8.3'


group :test, :development do
  gem 'rspec-rails'
  gem 'its'
end

group :test do
  gem 'coveralls', '0.7.0'
  gem 'shoulda-matchers', '2.6.1'
  gem 'database_cleaner', '1.3.0'
  gem 'webmock', '1.20.0'
end

还有我的Gemfile.lock

    GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (4.1.7)
      actionpack (= 4.1.7)
      actionview (= 4.1.7)
      mail (~> 2.5, >= 2.5.4)
    actionpack (4.1.7)
      actionview (= 4.1.7)
      activesupport (= 4.1.7)
      rack (~> 1.5.2)
      rack-test (~> 0.6.2)
    actionview (4.1.7)
      activesupport (= 4.1.7)
      builder (~> 3.1)
      erubis (~> 2.7.0)
    active_model_serializers (0.9.0)
      activemodel (>= 3.2)
    activemodel (4.1.7)
      activesupport (= 4.1.7)
      builder (~> 3.1)
    activerecord (4.1.7)
      activemodel (= 4.1.7)
      activesupport (= 4.1.7)
      arel (~> 5.0.0)
    activesupport (4.1.7)
      i18n (~> 0.6, >= 0.6.9)
      json (~> 1.7, >= 1.7.7)
      minitest (~> 5.1)
      thread_safe (~> 0.1)
      tzinfo (~> 1.1)
    addressable (2.3.8)
    archive-tar-minitar (0.5.2)
    arel (5.0.1.20140414130214)
    bcrypt (3.1.11)
    builder (3.2.2)
    concurrent-ruby (1.0.2)
    coveralls (0.7.0)
      multi_json (~> 1.3)
      rest-client
      simplecov (>= 0.7)
      term-ansicolor
      thor
    crack (0.4.3)
      safe_yaml (~> 1.0.0)
    database_cleaner (1.3.0)
    devise (4.2.0)
      bcrypt (~> 3.0)
      orm_adapter (~> 0.1)
      railties (>= 4.1.0, < 5.1)
      responders
      warden (~> 1.2.3)
    devise_ldap_authenticatable (0.8.5)
      devise (>= 3.4.1)
      net-ldap (>= 0.6.0, <= 0.11)
    diff-lcs (1.2.5)
    docile (1.1.5)
    docker-api (1.13.0)
      archive-tar-minitar
      excon (>= 0.37.0)
      json
    domain_name (0.5.20160615)
      unf (>= 0.0.5, < 1.0.0)
    erubis (2.7.0)
    excon (0.50.1)
    faraday (0.8.11)
      multipart-post (~> 1.2.0)
    faraday_middleware (0.9.0)
      faraday (>= 0.7.4, < 0.9)
    fleet-api (1.1.0)
      excon (>= 0.27.4)
    http-cookie (1.0.2)
      domain_name (~> 0.5)
    i18n (0.7.0)
    its (0.2.0)
      rspec-core
    json (1.8.3)
    kmts (2.0.1)
    mail (2.6.4)
      mime-types (>= 1.16, < 4)
    mime-types (3.1)
      mime-types-data (~> 3.2015)
    mime-types-data (3.2016.0521)
    minitest (5.9.0)
    multi_json (1.12.1)
    multipart-post (1.2.0)
    net-ldap (0.11)
    netrc (0.11.0)
    octokit (3.2.0)
      sawyer (~> 0.5.3)
    orm_adapter (0.5.0)
    puma (2.8.2)
      rack (>= 1.1, < 2.0)
    rack (1.5.5)
    rack-test (0.6.3)
      rack (>= 1.0)
    rails (4.1.7)
      actionmailer (= 4.1.7)
      actionpack (= 4.1.7)
      actionview (= 4.1.7)
      activemodel (= 4.1.7)
      activerecord (= 4.1.7)
      activesupport (= 4.1.7)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.1.7)
      sprockets-rails (~> 2.0)
    railties (4.1.7)
      actionpack (= 4.1.7)
      activesupport (= 4.1.7)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (11.2.2)
    responders (1.1.2)
      railties (>= 3.2, < 4.2)
    rest-client (2.0.0)
      http-cookie (>= 1.0.2, < 2.0)
      mime-types (>= 1.16, < 4.0)
      netrc (~> 0.8)
    rspec-core (3.5.1)
      rspec-support (~> 3.5.0)
    rspec-expectations (3.5.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.5.0)
    rspec-mocks (3.5.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.5.0)
    rspec-rails (3.5.0)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-core (~> 3.5.0)
      rspec-expectations (~> 3.5.0)
      rspec-mocks (~> 3.5.0)
      rspec-support (~> 3.5.0)
    rspec-support (3.5.0)
    safe_yaml (1.0.4)
    sawyer (0.5.5)
      addressable (~> 2.3.5)
      faraday (~> 0.8, < 0.10)
    shoulda-matchers (2.6.1)
      activesupport (>= 3.0.0)
    simplecov (0.12.0)
      docile (~> 1.1.0)
      json (>= 1.8, < 3)
      simplecov-html (~> 0.10.0)
    simplecov-html (0.10.0)
    sprockets (3.6.3)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (2.3.3)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      sprockets (>= 2.8, < 4.0)
    sqlite3 (1.3.9)
    term-ansicolor (1.3.2)
      tins (~> 1.0)
    thor (0.19.1)
    thread_safe (0.3.5)
    tins (1.10.2)
    tzinfo (1.2.2)
      thread_safe (~> 0.1)
    unf (0.1.4)
      unf_ext
    unf_ext (0.0.7.2)
    warden (1.2.6)
      rack (>= 1.0)
    webmock (1.20.0)
      addressable (>= 2.3.6)
      crack (>= 0.3.2)

PLATFORMS
  ruby

DEPENDENCIES
  active_model_serializers (= 0.9.0)
  coveralls (= 0.7.0)
  database_cleaner (= 1.3.0)
  devise
  devise_ldap_authenticatable
  docker-api (= 1.13.0)
  faraday_middleware (= 0.9.0)
  fleet-api (= 1.1.0)
  its
  json (= 1.8.3)
  kmts (= 2.0.1)
  octokit (= 3.2.0)
  puma (= 2.8.2)
  rails (= 4.1.7)
  rspec-rails
  shoulda-matchers (= 2.6.1)
  sqlite3 (= 1.3.9)
  webmock (= 1.20.0)

BUNDLED WITH
   1.12.5

记住:问题是当我做 docker build

感谢您的帮助

【问题讨论】:

  • 能不能像“make: not found”这么简单??如果您运行带有容器的 shell 是否存在?
  • 如果无法创建容器,如何运行shell?

标签: ruby-on-rails json ruby-on-rails-3 docker rubygems


【解决方案1】:

与任何 Ruby 安装一样,您需要开发工具来安装带有本机扩展的 gem:

RUN apk update \
 && apk add --no-cache  \
    build-base  \
    ruby-dev

【讨论】:

    【解决方案2】:

    panamax-ui 使用 Alpine Linux 基础镜像,所以你可以尝试将ruby-json apk 包添加到 Dockerfile 以正确安装 json gem:

    FROM centurylink/panamax-ruby-base:0.4.0
    
    RUN apk-install ruby-json
    
    CMD bundle exec rails s
    

    【讨论】:

    • 问题出现在 FROM 行中
    • 您可以尝试将行从基本映像 (github.com/CenturyLinkLabs/panamax-ruby-base/blob/master/…) 复制到您的 Dockerfile 并在那里添加“ruby-json”包。
    • 干得好,先生!你可以编辑你的答案并通知我,我会检查它是否成功:)
    • 这对我来说是正确的解决方案。 Alpine Linux 是一个最小的映像,许多在其他发行版上被视为理所当然的库在 Alpine 中默认不存在。 ruby-json 包允许 json gem 在 Alpine Linux 3.5 上编译其本机扩展。
    • 警告 对于像 alpine 3.9 这样的版本,正确的 RUN 是 RUN apk add ruby-json。顺便说一句:在某些情况下,您可能需要更多的本机库。你可以在这里找到有用的东西 - github.com/gliderlabs/docker-alpine/issues/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-10
    • 2019-09-09
    • 1970-01-01
    • 2012-05-31
    • 2012-03-28
    • 2016-05-02
    相关资源
    最近更新 更多