我继承了一个非常老的应用程序,该应用程序是使用ruby 1.8.7和postgres构建的,我正试图为此创建一个docker映像。
来自这张图片https://hub.docker.com/r/hublogix/minimal-ruby/ 我已将应用程序代码添加到图像。
所以现在我在图像中,我可以看到:
bash-4.3# ls
Capfile REVISION Rakefile app config config.ru db doc lib public script test tmp vendor
bash-4.3#
bash-4.3# gem install rake
Fetching: rake-12.3.1.gem (100%)
ERROR: Error installing rake:
rake requires Ruby version >= 2.0.0.
bash-4.3#
config / environment.rb就像:
# Be sure to restart your server when you modify this file
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.16' unless defined? RAILS_GEM_VERSION
APP_NAME = "App name"
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
config.gem "inherited_resources",
:source => "http://gemcutter.org",
:version => "1.0.1"
config.gem "has_scope",
:lib => "has_scope",
:source => 'http://gemcutter.org',
:version => "0.4.1"
config.gem "haml"
config.gem "will_paginate",
:lib => "will_paginate",
:source => "http://gemcutter.org"
config.gem "searchlogic",
:lib => "searchlogic",
:source => "http://gemcutter.org",
:version => "2.4.11"
config.gem "paperclip",
:lib => "paperclip",
:source => "http://gemcutter.org",
:version => "2.3.1.1"
config.gem "clearance",
:lib => "clearance",
:source => "http://gemcutter.org",
:version => "0.8.8"
config.gem "rsl-stringex",
:lib => "stringex",
:source => "http://gems.github.com",
:version => "1.0.3"
config.gem 'formtastic',
:lib => "formtastic",
:version => "0.9.7"
config.gem "acts_as_audited",
:lib => "acts_as_audited",
:version => "1.1.0"
config.gem "prawn",
:version => "0.8.4"
config.gem "htmlentities",
:version => "4.2.0"
config.gem "emap_single_sign_on"
config.gem "rmagick",
:lib => "RMagick"
config.load_paths += %W( #{Rails.root}/app/mailers #{Rails.root}/app/observers #{Rails.root}/app/sweepers )
config.load_paths += %W( #{Rails.root}/app/presenters #{Rails.root}/app/reports)
config.frameworks -= [ :active_resource ]
# config.active_record.observers = :name
config.time_zone = 'UTC'
end
GOOGLE_ANALYTICS_TRACKING_CODE = ""
当我尝试运行它时,我从容器中收到此错误:
/usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:900:in `report_activate_error': Could not find RubyGem rack (~> 1.1.0) (Gem::LoadError)
from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:248:in `activate'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:1276:in `gem'
from /usr/src/vendor/rails/actionpack/lib/action_controller.rb:34
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /usr/src/vendor/rails/activesupport/lib/active_support/dependencies.rb:182:in `require'
from /usr/src/vendor/rails/activesupport/lib/active_support/dependencies.rb:547:in `new_constants_in'
from /usr/src/vendor/rails/activesupport/lib/active_support/dependencies.rb:182:in `require'
from /usr/src/vendor/rails/railties/lib/commands/server.rb:2
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from ./script/server:3
助产士列表:
actionmailer (2.3.17)
actionpack (2.3.17)
activerecord (2.3.17)
activeresource (2.3.17)
activesupport (2.3.17)
andre-geokit (1.2.5)
backup (3.0.25)
builder (3.2.2)
bundler (1.5.3)
excon (0.31.0)
fastercsv (1.5.5, 1.5.4)
formatador (0.2.4)
geocoder (1.1.9)
haml (4.0.5, 2.0.9)
json (1.8.1)
mislav-will_paginate (2.3.11)
multi_json (1.9.0)
mysql (2.9.1, 2.8.1)
newrelic_rpm (3.7.3.204)
nokogiri (1.4.2, 1.4.1)
open4 (1.3.3)
puma (2.8.1)
rack (1.1.6, 1.1.0)
rails (2.3.17)
rake (10.1.1)
rdoc (4.1.1)
RedCloth (4.2.9)
right_aws (3.1.0)
right_http_connection (1.4.0)
rmagick (2.13.3, 2.13.2)
rubyist-aasm (2.0.5)
stringex (1.2.0)
thor (0.15.4)
thoughtbot-paperclip (2.2.9.2)
tilt (2.0.0)
我有具有所有依赖项的vendor文件夹,但是我不清楚在docker中安装基础系统还需要做什么?
关于如何使该应用程序在docker中运行或如何构建的任何建议?
答案 0 :(得分:1)
当您通过rake
手动安装gem install rake
gem时,gem tries to install the latest version. But the latest version of
rake`不再支持您的旧版本Ruby。相反,您需要选择一个仍适用于Ruby 1.8.7的版本。
但这只是您问题的一部分。您的问题是您需要安装应用程序的所有依赖项,而没有任何信息您的应用程序可能具有哪些依赖项。
由于Ruby on Rails 3.0 bundler
用于管理依赖项。我强烈建议您通过adding bundler
and a Gemfile
to your application开始解决问题。
请记住,您只有非常有限的信息,您的应用程序可能具有哪些依赖性。您知道这是针对于2008年中发布的Ruby 1.8.7构建的。因此,我想您的应用程序是在2008–2010年构建的(2010年之后,开发人员可能会使用Ruby 1.9.x)。
当时rake
的最新版本是~> 0.8.3
(请参阅rake
versions)。此外,我猜您的应用程序使用Ruby on Rails 2.x
(请参阅rails
versions)。在<3.0
Rails应用程序中,通常可以在config/environment.rb
中找到分配给RAILS_GEM_VERSION
的Rails版本。我假设它是2.3.5
。使用您的应用程序根目录中的以下信息创建一个Gemfile
:
source 'https://rubygems.org'
gem 'rails', '2.3.5'
gem 'rake', '~> 0.8.7'
通过运行bundle install
安装这些gem,然后尝试打开rails控制台或启动应用程序服务器。这很可能行不通,您将需要添加更多的gem作为对Gemfile
的依赖。
我想您需要添加以下内容:
gem 'rack', '~> 0.9.0'
gem 'mysql', '2.8.1'
仔细查看错误消息,例如,如果Ruby抱怨缺少名称为foo
的gem,请查看Rubygems周围可用的foo
gem版本2008-2010,并将gem 'foo', '<version number>'
添加到您的Gemfile
中,然后再次运行bundle install
。
以这种方式查找所有必需的依赖关系并不容易,而且要找到特定版本的工作集甚至更加困难。但是,如果没有更多信息,这是恕我直言的最佳开始方法。祝你好运!