Phusion Passenger Docker 图片上的错误 "Could not find rake-10.5.0 in any of the sources"

Error "Could not find rake-10.5.0 in any of the sources" on Phusion Passenger Docker image

我正在尝试使用 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/*

我试过 运行ning 捆绑器作为 RUN bundle install --deployment,但效果不佳。我通过 rails-env.conf 文件传递​​ RAILS_ENVPASSENGER_APP_ENV 并且它们都设置为生产(根据 Passenger 图像文档,这是默认设置)。

如果我 docker exec -it bash <ID> 进入容器并且 运行 gem list 我看到所有的 gem 都安装了,所以我不知道出了什么问题。

此错误是由于软件过时所致。由于乘客图像不会经常更新,因此重要的是在您的 Dockerfile 中更新所有内容。这就是我通常如何根据 phusion 图像设置 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 版本中更新。应该经常碰一下。

我还确保 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 的部分。

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

修复它

rake rails:update

玩得开心!