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

How do I setup a puma.rb file in rails

好的,我正在尝试将 Docker 设置到现有的 rails 应用程序。 我正在关注指南,但指南使用的是 Unicorn 服务器。我需要使用 Puma。

假设我的 /Docker 文件如下所示:

 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

正常配置 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 添加到 environment 节点上的 docker-compose.yml 配置文件中。