1

I've made a simple Ruby api, using Sinatra. It accesses an mlabs mongodb using Mongoid. If I run docker-compose build followed by docker-compose up, I can access and use the api on localhost. However, if I push and release to Heroku using heroku container:push web and heroku container:release web, it crashes a few seconds after starting. The Heroku logs don't provide much info:

2019-03-07T17:40:33.307048+00:00 app[api]: Release v10 created by user ****@gmail.com
2019-03-07T17:40:33.307048+00:00 app[api]: Deployed web (4cd454c25995) by user user ****@gmail.com
2019-03-07T17:40:33.485337+00:00 heroku[web.1]: State changed from crashed to starting
2019-03-07T17:40:56.940967+00:00 heroku[web.1]: Starting process with command `irb`
2019-03-07T17:40:59.715826+00:00 heroku[web.1]: State changed from starting to crashed
2019-03-07T17:40:59.696826+00:00 heroku[web.1]: Process exited with status 0
2019-03-07T17:40:59.630419+00:00 app[web.1]: Switch to inspect mode.
2019-03-07T17:40:59.631325+00:00 app[web.1]: 

My Dockerfile:

FROM ruby:2.5.3

RUN apt-get update -qq && apt-get install -y build-essential
RUN gem install bundler

ENV APP_HOME /app
RUN mkdir $APP_HOME
WORKDIR $APP_HOME

ADD Gemfile* $APP_HOME/
ADD mongoid.config $APP_HOME/
RUN bundle install

ADD . $APP_HOME

My docker-compose.yml:

version: "2"
services:
  web:
    build: .
    command: bundle exec ruby server.rb
    ports:
      - "80:4567"

My Mongoid configuration (mongoid.config):

development:
  clients:
    default:
      uri: mongodb://myUsername:myPassword@hostAddress:hostPort/databaseName

Where myUsername, myPassword, hostAddress, hostPort and databaseName is switched out for the actual values.

In my ruby file, I load the Mongoid configuration with Mongoid.load! "mongoid.config".

My Gemfile, for completeness:

source 'https://rubygems.org'

gem 'sinatra'
gem 'mongoid'
gem 'sinatra-contrib'

Does anyone have an idea on how I can find out what causes the crash?

mikk2168
  • 11
  • 1
  • you can try to SSH Into the machine and start the server manually. That way you will see the full errors. You can also change the log level on Heroku, to see more logs (see https://stackoverflow.com/a/28330485/2981429) – max pleaner Mar 07 '19 at 19:43
  • looks like something trivial as not uploading the mongodb service in the docker-compose file. it will run locally if you have mongod running locally but not on remote as it canr resolve hostAddress:hostPort from inside the ruby container. can you provide more information? – It-Z Mar 25 '19 at 14:30

0 Answers0