Skip to content

Instantly share code, notes, and snippets.

Last active July 22, 2022 22:00
What would you like to do?
How to dockerize #rails app with #puma. Edit config/application.rb and config/puma.rb #docker #ruby
module YourApplicationName
class Application < Rails::Application
# ...
# We want to set up a custom logger which logs to STDOUT.
# Docker expects your application to log to STDOUT/STDERR and to be ran
# in the foreground.
config.log_level = ENV.fetch('LOG_LEVEL', :debug)
config.log_tags = [:subdomain, :uuid]
config.logger =
# ...
api: bundle exec puma -C config/puma.rb
# Before configuring Puma, you should look up the number of CPU cores your server has, change this to match your CPU core count
workers Integer(ENV['WEB_CONCURRENCY'] || [1, `grep -c processor /proc/cpuinfo`.to_i].max)
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count
rackup DefaultRackup
# HTTP interface
port 3000
# HTTPS inteface
# How to generate certificate:
ssl_bind '', '3001', { key: 'ssl/server.key', cert: 'ssl/server.crt' }
environment ENV['RACK_ENV'] || 'development'
stdout_redirect(stdout = '/dev/stdout', stderr = '/dev/stderr', append = true)
on_worker_boot do
# Worker specific setup for Rails 4.1+
# See:
Copy link

nroose commented Jun 26, 2019

Any thoughts on Delayed::Jobs?

Copy link

andrius commented Jul 7, 2019

Any thoughts on Delayed::Jobs?

Thing that within docker such things as Sidekiq, Que or delayed jobs should be running within another container as a separate process, that's how docker suggest to manage things (one process in container), so

FROM andrius/alpine-ruby

# all the stuff you want to add

CMD ["bundle", "exec", "some_delayed_job_application"]

Copy link

kuyseng commented Jan 22, 2020

Hi @andrius. Could help to share Dockerfile to build image? And i'm not sure multiple workers can run in single docker process. Help to explain too. Thanks in advance

Copy link

andrius commented May 31, 2020

Many months ago :) Perhaps answer is not relevant, anyways:

docker want us to run a single process, with ruby I do not see any problem, just run two instances in this case, i.e.:

Shared code with all the models, classes and controllers in Dockerfile.base:



COPY . .

RUN bundle install

GUI Dockerfile.gui:

FROM base
CMR ["bundle", "exec", "rails", "server", ""]

Workers Dockerfile.workers:

FROM base
CMR ["bundle", "exec", "sidekiq", "... args ..."]
docker build --pull --force-rm -t base --file ./Dockerfile.base .
docker build --pull --force-rm -t gui --file ./Dockerfile.gui .
docker build --pull --force-rm -t workers --file ./Dockerfile.workers .

So then we can run them separately. There is more options, i.e. we can use supervisord to handle multiple processes with docker, i.e. based on this example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment