Rails 捆绑包安装失败 Docker

Rails Bundle Install failed with Docker

我尝试用 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 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 没有用。

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

Cannot allocate memory - /usr/local/bin/ruby -r ./siteconf20180911-15-1atjs2q.rb extconf.rb 2>&1

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

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

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

使用 ruby 的高山版本。它会消耗更少space。例如:FROM ruby:2.5.1-alpine