首页 > 解决方案 > Docker Ruby Bundler 未安装

问题描述

我的 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 系统。以前有人遇到过这个问题吗?任何帮助表示赞赏。

先感谢您。

标签: rubydockerdockerfilebundler

解决方案


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 .

这个问题得到了解决。

感谢您抽出时间。


推荐阅读