错误"无法在任何来源中找到rake-10.5.0"在Phusion Passenger Docker图像上

时间:2016-02-08 04:33:10

标签: ruby-on-rails docker passenger docker-compose

我正在尝试使用Docker和Phusion Passenger Ruby base image部署Rails应用,但每当我尝试从浏览器访问应用时,我都会收到此错误:

web_1 | [ 2016-02-08 04:18:44.6861 31/7ff292141700     age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application   /home/app/webapp: An error occurred while starting up the preloader.
web_1 |   Error ID: d3103e16
web_1 |   Error details saved to: /tmp/passenger-error-EwymlW.html
web_1 |   Message from application: <p>It looks like Bundler could not find a gem. Maybe you didn't install all the gems that this application needs. To install your gems, please run:</p>
web_1 |
web_1 |   <pre class="commands">bundle install</pre>
web_1 |
web_1 | <p>If that didn't work, then the problem is probably caused by your application being run under a different environment than it's supposed to. Please check the following:</p>
web_1 |
web_1 | <ol>
web_1 |   <li>Is this app supposed to be run as the <code>app</code> user?</li>
web_1 |   <li>Is this app being run on the correct Ruby interpreter? Below you will
web_1 |       see which Ruby interpreter Phusion Passenger attempted to use.</li>
web_1 | </ol>
web_1 |
web_1 | <p>-------- The exception is as follows: -------</p>
web_1 | Could not find rake-10.5.0 in any of the sources (Bundler::GemNotFound)
web_1 | <pre>  /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/spec_set.rb:92:in `block in materialize&#39;
web_1 |   /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/spec_set.rb:85:in `map!&#39;
web_1 |   /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/spec_set.rb:85:in `materialize&#39;
web_1 |   /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/definition.rb:140:in `specs&#39;
web_1 |   /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/definition.rb:185:in `specs_for&#39;
web_1 |   /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/definition.rb:174:in `requested_specs&#39;
web_1 |   /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/environment.rb:18:in `requested_specs&#39;
web_1 |   /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:13:in `setup&#39;
web_1 |   /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler.rb:127:in `setup&#39;
web_1 |   /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/setup.rb:18:in `&lt;top (required)&gt;&#39;
web_1 |   /usr/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require&#39;
web_1 |   /usr/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require&#39;
web_1 |   /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:430:in `activate_gem&#39;
web_1 |   /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:297:in `block in run_load_path_setup_code&#39;
web_1 |   /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:435:in `running_bundler&#39;
web_1 |   /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:296:in `run_load_path_setup_code&#39;
web_1 |   /usr/share/passenger/helper-scripts/rack-preloader.rb:100:in `preload_app&#39;
web_1 |   /usr/share/passenger/helper-scripts/rack-preloader.rb:156:in `&lt;module:App&gt;&#39;
web_1 |   /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `&lt;module:PhusionPassenger&gt;&#39;
web_1 |   /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `&lt;main&gt;&#39;</pre>
web_1 |
web_1 |
web_1 | [ 2016-02-08 04:18:44.6935 31/7ff293143700 age/Cor/Con/CheckoutSession.cpp:277 ]: [Client 1-2] Cannot checkout session because a spawning error occurred. The identifier of the error is d3103e16. Please see earlier logs for details about the error.

这是我的Dockerfile

FROM phusion/passenger-ruby22:0.9.18

# Set correct environment variables.
ENV HOME /root

# Use baseimage-docker's init process.
CMD ["/sbin/my_init"]

# Enable Nginx/Passenger
RUN rm -f /etc/service/nginx/down

# Enable portals virtual host
RUN rm /etc/nginx/sites-enabled/default
COPY portals.conf /etc/nginx/sites-enabled/portals.conf
RUN mkdir /home/app/webapp

# Load env vars into nginx
COPY rails-env.conf /etc/nginx/main.d/rails-env.conf

# Install gems dependencies
COPY Gemfile* /tmp/
WORKDIR /tmp
RUN bundle install

# Copy rails app
WORKDIR /home/app/webapp
COPY . ./
RUN chown -R app:app ./

# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

我尝试将捆绑程序作为RUN bundle install --deployment运行,但它也不起作用。我通过RAILS_ENV文件传递PASSENGER_APP_ENVrails-env.conf,并且它们都已设置为生产(根据Passenger图像文档,这是默认设置)。

如果我docker exec -it bash <ID>进入容器并运行gem list我发现所有宝石都已安装,所以我不知道错误。

2 个答案:

答案 0 :(得分:2)

此错误是由于软件过期造成的。由于乘客图像不经常更新,因此在Dockerfile中更新所有内容非常重要。这就是我通常根据错误图像设置Dockerfile的方式:

FROM phusion/passenger-ruby22:0.9.18

ENV SYSTEM_UPDATE=1
RUN apt-get update \
&& apt-get upgrade -y -o Dpkg::Options::="--force-confold" \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /home/app
COPY Gemfile /home/app/Gemfile
COPY Gemfile.lock /home/app/Gemfile.lock
RUN gem update --system && \
gem update bundler && \
bundle install --jobs 4 --retry 5

# The rest of your app setup here

ENTRYPOINT ["/sbin/my_init", "--"]

SYSTEM_UPDATE只是一个缓存生成器变量。当我碰到这个时,所有的包都会在下一个docker build上更新。它应该频繁碰撞。

我还确保gembundler在运行bundle install之前完全保持最新状态。

此外,将GemfileGemfile.lock复制到tmp目录没有任何好处,只需将其复制到您的应用程序目录即可。

你可以删除你的最终Clean up APT when done.命令 - 这真的不是正确的地方。应该有一条RUN行在一个层中运行所有apt-get命令。

请查看https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/,了解有关设置Dockerfile的最佳做法,尤其是有关使用apt-get的部分。

答案 1 :(得分:0)

对我来说,rake在那里,我用

修复它

rake rails:update

玩得开心!