我使用Sinatra制作了一个简单的Ruby API。它使用Mongoid访问mlabs mongodb。如果先运行docker-compose build
,然后运行docker-compose up
,则可以访问和使用localhost上的api。但是,如果我使用heroku container:push web
和heroku container:release web
推送并释放到Heroku,它将在启动后几秒钟崩溃。 Heroku日志没有提供太多信息:
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]:
我的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
我的docker-compose.yml:
version: "2"
services:
web:
build: .
command: bundle exec ruby server.rb
ports:
- "80:4567"
我的Mongoid配置(mongoid.config):
development:
clients:
default:
uri: mongodb://myUsername:myPassword@hostAddress:hostPort/databaseName
将myUsername,myPassword,hostAddress,hostPort和databaseName切换为实际值。
在我的ruby文件中,我用Mongoid.load! "mongoid.config"
加载Mongoid配置。
我的Gemfile,出于完整性考虑:
source 'https://rubygems.org'
gem 'sinatra'
gem 'mongoid'
gem 'sinatra-contrib'
有人知道我如何找出导致崩溃的原因吗?