ruby - 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 系统。以前有人遇到过这个问题吗?任何帮助表示赞赏。
先感谢您。
解决方案
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 很好,但由于 rubygems.org 的 IPV6 仍然被破坏并在 docker 内部获取时产生问题。所以,我使用主机网络运行命令。
docker image build --network=host -t my-app .
这个问题得到了解决。
感谢您抽出时间。
推荐阅读
- android - 在 Android Studio 4.0(Canary) 中找不到预览窗口的位置
- typescript - 如何扩展 $options 属性的类型?
- javascript - 如何仅使用 Node.js 后端代码将浏览器重定向到另一个站点?
- git - 如何防止“开发”被合并到“发布”中?
- python - 为什么我收到的 ARP 数据包总是有相同的 MAC 地址?
- emacs - 每次我重新安排任务时如何插入预定时间来记录
- google-cloud-platform - 允许每个用户拥有 Google Cloud Storage 对象所有权的 IAM/ACL 政策
- node.js - ReferenceError:尝试在 linux 的命令行上运行灯塔报告时未定义 URL
- scala - 如何修复 Spark 聚合最大值 ` 错误中包含无效字符?
- neo4j - 有没有办法在 Neo 中为关系创建唯一约束