【问题标题】:Docker Ruby Bundler not installingDocker Ruby Bundler 未安装
【发布时间】:2020-07-28 13:25:48
【问题描述】:

我的 Dockerfile 如下所示:

FROM ruby:2.5-alpine

RUN apk update add --no-cache build-base nodejs postgresql-dev

RUN mkdir /my-app
WORKDIR /my-app

COPY Gemfile Gemfile.lock ./
RUN bundle install --binstubs

COPY . .

CMD puma -C config/puma.rb

现在当我尝试创建图像时,出现以下错误:

You must use Bundler 2 or greater with this lockfile.
The command '/bin/sh -c bundle install --binstubs' returned a non-zero code: 20

使用的捆绑器版本 Gemfile.lock 是 2.1.4。 我确实尝试在 Dockerfile 中添加以下行:

RUN gem update --system
RUN gem install bundler -v 2.1.4

在这种情况下,我收到以下错误:

ERROR:  Could not find a valid gem 'bundler' (= 2.1.4), here is why:
          Unable to download data from https://rubygems.org/ - no such name (https://rubygems.org/specs.4.8.gz)

我使用的是 Ubuntu 18.04 系统。以前有人遇到过这个问题吗?任何帮助表示赞赏。

提前谢谢你。

【问题讨论】:

  • 您在哪里添加了此安装捆绑程序行?因为当我这样做时它可以工作(从来没有得到--binstubs的警告/错误),此外,如果我添加“RUN gem update --system && gem install bundler && bundle --version”它会安装2.1.4,不指定版本时得到的版本是什么?
  • 我在 WORKDIR 行之后添加了 install bundler 行。我指定了捆绑器版本 2.1.4,但它从未安装。它在RUN gem update --system 处引发错误

标签: ruby docker dockerfile bundler


【解决方案1】:
FROM ruby:2.5-alpine

RUN apk update add --no-cache build-base nodejs postgresql-dev

RUN mkdir /my-app
WORKDIR /my-app

RUN gem update --system
RUN gem install bundler -v 2.1.4
COPY Gemfile Gemfile.lock ./
RUN bundle install --binstubs

COPY . .

CMD puma -C config/puma.rb

所以,安装 bundler 没问题,但由于 ruby​​gems.org 的 IPV6 仍然损坏,并且在 docker 内部获取时产生问题。所以,我使用主机网络运行命令。

docker image build --network=host -t my-app .

这个问题已经解决了。

感谢您抽出宝贵时间。

【讨论】:

    【解决方案2】:

    我需要创建一个答案,因为我无法将这一切都发布到评论中。我知道这不是您的解决方案。

    如果我使用此设置,它运行时不会出错。你能看看它与你的设置和测试有什么不同吗? (也请将此添加到问题中)

    dockerfile

    FROM ruby:2.5-alpine
    
    RUN apk update add --no-cache build-base nodejs postgresql-dev
    
    RUN mkdir /my-app
    WORKDIR /my-app
    
    RUN gem update --system && gem install bundler && bundle --version 
    # installs bundler 2.1.4
    
    COPY Gemfile Gemfile.lock ./
    RUN bundle install
    
    COPY . .
    
    CMD /bin/sh
    

    宝石文件

    ruby '2.5.8'
    source 'https://rubygems.org'
    gem 'flay'
    

    Gemfile.lock

    GEM
      remote: https://rubygems.org/
      specs:
        erubis (2.7.0)
        flay (2.12.0)
          erubis (~> 2.7.0)
          path_expander (~> 1.0)
          ruby_parser (~> 3.0)
          sexp_processor (~> 4.0)
        path_expander (1.0.3)
        ruby_parser (3.13.1)
          sexp_processor (~> 4.9)
        sexp_processor (4.12.0)
    
    PLATFORMS
      ruby
    
    DEPENDENCIES
      flay
    
    RUBY VERSION
       ruby 2.5.8p224
    
    BUNDLED WITH
       2.1.4
    

    构建并开始于:

    docker build . --no-cache -t foobar
    docker run --it foobar
    

    【讨论】:

      猜你喜欢
      • 2020-02-26
      • 1970-01-01
      • 1970-01-01
      • 2019-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多