502 Bad gateway error/NameError in Rack application for sinatra app on nginx, passenger in a docker container

I am starting with docker (1.3.2) and I am trying to get an example working with nginx, passenger and sinatra. Nginx and passenger seem to work. However, I do not get my sinatra app to run. curl localhost gives a 502 bad gateway error and the same when I try to access in the browser. The question is why that happens and if this is docker related or a configuration issue?

If I place an index.html in public that gets served. If I start the app (see below) with rackup and curl localhost:9292 I get the expected reply.

  • Docker compose on docker swarm cluster separate containers on separate nodes
  • running incorrect docker image osx
  • View NodeJS Application Logs Via Cron Tasks on Supervisor on Docker
  • How to docker exec -ti CONTAINER_NAME /bin/bash on deployed docker stack?
  • Dockerizing simple webbapp: how to pick what goes in which container?
  • Iterate in RUN command in Dockerfile
  • The nginx error.log shows:

    request: "GET / HTTP/1.1", upstream: "passenger:/tmp/passenger.1.0.766/generation-0/request:", host: "localhost"
    App 812 stderr: [ 2015-02-09 16:19:54.3173 828/0x00000000b759a8(Worker 1) utils.rb:84 ]: *** Exception NameError in Rack application object (uninitialized constant Rack::MethodOverride::REQUEST_METHOD) (process 828, thread 0x00000000b759a8(Worker 1)):
    App 812 stderr:         from /var/lib/gems/2.1.0/gems/rack-1.6.0/lib/rack/methodoverride.rb:14:in `call'
    App 812 stderr:         from /var/lib/gems/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call'
    App 812 stderr:         from /var/lib/gems/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'
    App 812 stderr:         from /var/lib/gems/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'
    App 812 stderr:         from /var/lib/gems/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'
    App 812 stderr:         from /var/lib/gems/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'
    App 812 stderr:         from /usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request'
    App 812 stderr:         from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
    App 812 stderr:         from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
    App 812 stderr:         from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:455:in `block (3 levels) in start_threads'
    2015/02/09 16:19:54 [error] 786#0: *9 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: localhost,
    

    Googling for the error message I could not find anything useful. I also tried to set-up the example described here: https://www.linode.com/docs/websites/frameworks/sinatra-framework-and-nginx-on-debian-6-squeeze
    with the same results as above.

    My directory structure:
    /home/app/sinatra-test/config.ru
    /home/app/sinatra-test/app.rb
    /home/app/sinatra-test/public/
    /etc/nginx/sites-enabled/sinatra-test

    config.ru:

    require 'rubygems'
    require './app'
    run Sinatra::Application
    

    app.rb:

    require 'sinatra'
    
    get '/' do
      "Hello from Sinatra!"
    end
    

    nginx config in sinatra-test:

    server {
      server_name localhost;
      listen 80;
      root /home/app/sinatra-test/public;
    
      passenger_enabled on;
      passenger_user app;
      passenger_ruby /usr/bin/ruby2.1;
    }
    

  • How to monitor java application memory usage in Docker
  • Where does docker-machine save the configuration on a remote Ubuntu host running systemd?
  • Network between 2 docker-composes
  • Docker Keep Exiting (Deploying MS SQL on MAC osx)
  • PFX file to docker daemon tls
  • This site can't be reached docs/docker.github.io
  • 2 Solutions collect form web for “502 Bad gateway error/NameError in Rack application for sinatra app on nginx, passenger in a docker container”

    Further reading lead to this http://blog.baroquebobcat.com/category/tech/ which pointed to the answer – a mismatch in the rack version installed and the one sinatra requires. I was using the phusion passenger docker image which contained rack 1.6.0. Downgrading to 1.4.0 solved the issue.

    I am the Phusion Passenger author. We have recently received a question from another user who experienced this same issue. The cause of the issue is pretty much as ikkjo described it. The solution is to use a Gemfile.

    We have documented the issue and its solution on the Passenger Github issue tracker: https://github.com/phusion/passenger/issues/1478#issuecomment-93730487

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.