【问题标题】:Rails Bundle Install failed with DockerRails Bundle Install 使用 Docker 失败
【发布时间】:2018-09-11 10:42:33
【问题描述】:

我尝试使用 docker 安装 Rails,但出现以下错误

Installing websocket-driver 0.6.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/usr/local/bundle/gems/websocket-driver-0.6.5/ext/websocket-driver
/usr/local/bin/ruby -r ./siteconf20180911-15-1atjs2q.rb extconf.rb
Cannot allocate memory - /usr/local/bin/ruby -r ./siteconf20180911-15-1atjs2q.rb
extconf.rb 2>&1

Gem files will remain installed in /usr/local/bundle/gems/websocket-driver-0.6.5
for inspection.
Results logged to
/usr/local/bundle/extensions/x86_64-linux/2.5.0/websocket-driver-0.6.5/gem_make.out

An error occurred while installing websocket-driver (0.6.5), and Bundler cannot
continue.
Make sure that `gem install websocket-driver -v '0.6.5' --source
'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  rails was resolved to 5.1.6, which depends on
    actioncable was resolved to 5.1.6, which depends on
      websocket-driver

这是我的 docker 文件

FROM ruby:latest

RUN apt-get -y update && apt-get install -y curl

RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -

RUN apt-get -y update && apt-get -y install nodejs

RUN mkdir -p /app

WORKDIR /app

COPY . /app

RUN gem install rails

RUN  /app/bin/setup

RUN chmod -R 755 /app

EXPOSE 3000

CMD ["bundle", "exec", "puma", "-C", "config/puma.rb","-e","alpha"]

我尝试在我的 mac 机器上安装它,它运行良好。我从数字海洋购买了一个新的 ubuntu 16.04 服务器并尝试安装它。我得到了这个错误。我正在使用 Docker 版本 18.03.1-ce,构建 9ee9f40。

在我的 app/bin/setup 中,我在命令下运行

#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils

# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)

def system!(*args)
  system(*args) || abort("\n== Command #{args} failed ==")
end

chdir APP_ROOT do
  # This script is a starting point to setup your application.
  # Add necessary setup steps to this file.

  puts '== Installing dependencies =='
  system! 'gem install bundler --conservative'
  system('bundle check') || system!('bundle install')

  puts "\n== Removing old tempfiles =="
  system! 'bin/rails tmp:clear'

  puts "\n== Precompiling Assets =="
  system! 'bin/rails assets:precompile'

  puts "\n== Restarting application server =="
  system! 'bin/rails restart'
end

我尝试使用 ruby​​:latest, ruby​​:2.4.1 没有任何效果。

经过一些建议后,我在 Dockerfile 中添加了 sudo apt-get install ruby​​-dev 但这也不起作用

【问题讨论】:

    标签: ruby-on-rails ruby docker rubygems bundler


    【解决方案1】:

    无法分配内存 - /usr/local/bin/ruby -r ./siteconf20180911-15-1atjs2q.rb extconf.rb 2>&1

    此行表示您的 Digital Ocean 液滴没有足够的 RAM 来构建您的依赖项,因此 docker 构建失败。

    我也遇到了同样的问题,不幸的是你需要更多的资源。

    或者,您可以构建映像、标记并将其推送到 docker 存储库,然后在 DO droplet 上拉取并运行它,以避免构建步骤。

    【讨论】:

    • 这是不幸的答案,我也遇到了这个问题。在升级整个 droplet 之前,请检查还有什么正在使用内存。对我来说,这是当前运行 puma Web 服务器和其他东西的 docker 容器。您可以使用top 分析内存使用情况(按shift + > 一次以按MEM % 排序)。以bundle 开头的项目可能是以bundle exec 开头的ruby 进程。我停止了容器并重建它并且它起作用了。在构建时,我将其作为一种廉价的方式运行,以每秒捕获可用的内存:while sleep 1; do cat /proc/meminfo | grep MemFree >> ~/out; done
    【解决方案2】:

    使用高山版本的 ruby​​。它将消耗更少的空间。例如:FROM ruby:2.5.1-alpine

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-24
      • 1970-01-01
      • 2013-10-15
      • 1970-01-01
      • 2018-07-04
      • 2021-07-05
      • 1970-01-01
      相关资源
      最近更新 更多