在Docker容器中运行Rails应用程序

我想在一台debian机器上的Docker容器中运行Rails 4.2.1应用程序。

当我运行bundle exec rails时,出现这个错误:

Could not find json-1.7.7 in any of the sources Run `bundle install` to install missing gems. 

当我运行软件包安装时,我得到这个错误:

Gem :: Ext :: BuildError:错误:无法构buildgem原生扩展。

 /usr/local/rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150604-137-10l84fa. rb extconf.rb creating Makefile make "DESTDIR=" clean make "DESTDIR=" compiling generator.c In file included from generator.c:1:0: ../fbuffer/fbuffer.h: In function 'fbuffer_to_s': ../fbuffer/fbuffer.h:175:47: error: macro "rb_str_new" requires 2 arguments, but only 1 given VALUE result = rb_str_new(FBUFFER_PAIR(fb)); ^ ../fbuffer/fbuffer.h:175:20: warning: initialization makes integer from pointer without a cast VALUE result = rb_str_new(FBUFFER_PAIR(fb)); ^ Makefile:237: recipe for target 'generator.o' failed make: *** [generator.o] Error 1 make failed, exit code 2 Gem files will remain installed in /var/www/test/xyz/vendor/bundle/ruby/2 .2.0/gems/json-1.7.7 for inspection. Results logged to /var/www/test/xyz/vendor/bundle/ruby/2.2.0/extensions/x 86_64-linux/2.2.0/json-1.7.7/gem_make.out An error occurred while installing json (1.7.7), and Bundler cannot continue. Make sure that `gem install json -v '1.7.7'` succeeds before bundling. 

怎么了? 我现在能做什么?

docker-rails是我刚刚创build的一个项目,它使得docker(和CI) 非常容易 。 我认为它可以帮助你,并减less在docker上启动和运行rails所需的configuration。

它创build一个全局的共享gem卷(加快捆绑),并有一个示例Dockerfile使用。

鉴于本地错误,我猜你的Dockerfile缺less一个需要的软件包,你可能需要更新你的apt-get语句。

我得到了同样的错误。 这个错误是因为我们使用的ruby软件(gem)版本在某些时候不匹配。

你使用的是Ruby 2.2.1版本。 你的Gemfile包含了旧版本的gem,它取决于json版本1.7.7。

你应该安装下面的ruby版本:

 ruby-1.9.3-p448 

为了摆脱这个错误,或者更新与ruby 2.2.1版兼容的gem将会有所斩获。