如何在rails中设置puma.rb文件

时间:2018-03-30 19:36:52

标签: ruby-on-rails ruby docker puma

好的,我正在尝试将Docker设置为现有的rails应用。 我遵循指南,但指南使用的是Unicorn服务器。我需要使用Puma。

假设我的/ Dockerfile看起来像这样:

 FROM ruby:2.3.1
 RUN apt-get update -qq && apt-get install -y build-essential libpq-dev 
 postgresql-client
 ENV RAILS_ROOT /var/www/outtAttendance
 RUN mkdir -p $RAILS_ROOT/tmp/pids
 WORKDIR $RAILS_ROOT
 COPY Gemfile Gemfile
 COPY Gemfile.lock Gemfile.lock
 RUN gem install bundler
 RUN bundle install
 COPY config/puma.rb config/puma.rb
 COPY . .
 EXPOSE 3000
 CMD bundle exec puma -C config/puma.rb

我的config / puma.rb文件会是什么样的?

文件树是

 /MyApp
  /app
  /config
    /containers
      -puma.rb
 -Dockerfile

1 个答案:

答案 0 :(得分:1)

正常配置Puma:

# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count

port ENV.fetch("PORT") { 3000 }

# Specifies the `environment` that Puma will run in.
environment ENV.fetch("RAILS_ENV") { "development" }

# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart

不要忘记将PORTENVRAILS_MAX_THREADS添加到docker-compose.yml节点上的environment配置文件中。