DEV Community

Cover image for Dockerize a Rails 5, Postgres, Redis, Sidekiq and Action Cable Application with Docker Compose

Dockerize a Rails 5, Postgres, Redis, Sidekiq and Action Cable Application with Docker Compose

Nick Janetakis on April 18, 2018

This article was originally posted on Jul 8th 2016 at: https://nickjanetakis.com/blog/dockerize-a-rails-5-postgres-redis-sidekiq-action-cable-app-w...
Collapse
 
abhinavmsra profile image
Abhinav Mishra

All my projects are docker based. As much as I love using it, i hate the extra commands you need to run for trivial stuffs like starting a rails server, console or migrations.

I usually keep those scripts in bin/ folder and simply execute the file. This way its much more straightforward and can be documented in README file for new devs.

How do you feel about this approach?

Collapse
 
nickjj profile image
Nick Janetakis

Hi,

In that case I would ditch the scripts and just set up a few aliases at the Bash level. This way you can shorten up the command to almost what it would be without Docker, and you don't need to lug around scripts to each project.

I have some made to where I just type dew rails c and it opens a console by running docker-compose exec web rails c under the hood.

Collapse
 
abhinavmsra profile image
Abhinav Mishra

I agree but that still does not help much when you have some inexperienced developers in team.

Thread Thread
 
nickjj profile image
Nick Janetakis

Then make them experienced. :D

Collapse
 
biske profile image
Иван Бишевац

I agree with you.
Aliases are ok but I would prefer something that doesn't leak outside of the project.
So bin/ folder is better option IMHO.

Collapse
 
maestromac profile image
Mac Siri

I'm hoping to be completely reliant on docker as my sole development environment across my machines but I feel it's much slower than running ruby/rails natively. Did I make a mistake or is this slower performance expected?

Collapse
 
nickjj profile image
Nick Janetakis • Edited

Hi. What OS / version are you using and how exactly did you install Docker? On my 4 year old i5 3.2ghz Windows 10 box with an SSD a 10,000+ line Dockerized Rails project with 50+ top level gems detects and reloads code changes in under 100ms (faster than I can manually dart my eyes over to my browser and reload). Assets are a little bit slower to compile but it's definitely not disruptive.

There is nothing special about my set up. It's just stock Windows 10 pro (Fall 2017 update) using WSL (Ubuntu) and Docker for Windows (18.03).

Collapse
 
maestromac profile image
Mac Siri

MacOS High Sierra 10.13.4. I installed Docker via Docker CE 18.03.0. If I start up a server with docker, initial loading of localhost:300 takes 92 seconds!

My native rails/postgre initial load takes 21 seconds.

Collapse
 
msoedov profile image
Alex Miasoiedov • Edited
> RUN mkdir /app
>  WORKDIR /app

Just WORKDIR /app, since 2015 WORKDIR directive creates a dir if it does not exist

CMD puma -C config/puma.rb

CMD uses execvpe sys-call so it's better to pass arguments as a list

CMD ["puma",  "-C", "config/puma.rb"]

Collapse
 
nickjj profile image
Nick Janetakis

Thanks. I meant to change that so long ago (removing mkdir). Old habits die hard!

In the next orats release I'll update the Dockerfile and this post to reflect both changes.

Collapse
 
pbouillon profile image
Pierre Bouillon

You rock! Thanks for this tutorial !

Collapse
 
ben profile image
Ben Halpern

Nice thorough post Nick. @maestromac might be a good read.

Collapse
 
liana profile image
Liana Felt (she/her)

Docker is awesome.

I can see!

Collapse
 
andy profile image
Andy Zhao (he/him)

Phew, that's a thorough tutorial! Nice article!