I am trying to deploy a Rails app using Docker and the Phusion Passenger Ruby base image, but whenever I try to access the app from the browser I get this error:
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'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/spec_set.rb:85:in `map!'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/spec_set.rb:85:in `materialize'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/definition.rb:140:in `specs'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/definition.rb:185:in `specs_for'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/definition.rb:174:in `requested_specs'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/environment.rb:18:in `requested_specs'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:13:in `setup'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler.rb:127:in `setup'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/setup.rb:18:in `<top (required)>'
web_1 | /usr/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
web_1 | /usr/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
web_1 | /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:430:in `activate_gem'
web_1 | /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:297:in `block in run_load_path_setup_code'
web_1 | /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:435:in `running_bundler'
web_1 | /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:296:in `run_load_path_setup_code'
web_1 | /usr/share/passenger/helper-scripts/rack-preloader.rb:100:in `preload_app'
web_1 | /usr/share/passenger/helper-scripts/rack-preloader.rb:156:in `<module:App>'
web_1 | /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
web_1 | /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<main>'</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.
This is my 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/*
I tried running bundler as RUN bundle install --deployment
but it didn't work as well. I am passing RAILS_ENV
and PASSENGER_APP_ENV
via the rails-env.conf
file and they are both set to production (which is the default according to the Passenger image docs).
If I docker exec -it bash <ID>
into the container and run gem list
I see that all the gems are installed, so I don't know what's wrong.
This error is due to out of date software. Because the passenger images are not updated frequently it is important to bring everything up to date in your Dockerfile
. This is how I generally setup a Dockerfile
based off a phusion image:
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
is just a cache buster variable. When I bump that up all the packages will be updated on the next docker build. It should be bumped frequently.
I also ensure gem
and bundler
are fully up to date before running bundle install
.
Also, there is no benefit to copying your Gemfile
and Gemfile.lock
to the tmp directory, just copy it to your application directory.
You can remove your final Clean up APT when done.
command - that's really not the right place for that. There should be a single RUN
line that runs all the apt-get
commands in a single layer.
Take a look at https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/ for the best practices around setting up a Dockerfile, especially the sections about using apt-get.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments