Docker and docker-compose for development and production

I know it’s only partly an issue of Rails but I wish for a documentation and convention regarding the use of Docker and docker-compose. Every project has an ever slightly different setup for this. I really love it when I reach a new Rails project, run a docker-compose up and it installs and runs everything needed. All is there, rails, postgres, redis, memcached, mysql, sidekiq, sqlite3, clockwork, rspec, rubocop, bundle-audit, all the new yarn webpacker nodejs stuff (which I barely can follow), everything. To do it on my own is usually already quite complicated. Then I need to start to pass down ENV variables into everything. Which ones do I need, which ones does rails use? Then hell freezes up, when I try to create the docker images for production too and need to set (or not) various environment variables for production. Suddenly I also need asset compilation, db migrations and more. Also for me, docker was the only way to tame the javascript webpacker monster across multiple environments and OS. It is really a pain to setup your OS for a new rails project and docker was the best thing for me since a while.

There are just to many ways to do all of this and I wish for a sane default. I do not want prebuild docker images, since the combination possibilities are to big. (It’s probably the reason why there is no rails image available). I wish for some nicely prepared and thoroughly commented docker and docker-compose files to get most apps running in development, test and production.

Also, code reloading seems to break regularly in docker. This seems to be a docker issue.

config.file_watcher = ActiveSupport::EventedFileUpdateChecker
# => fix it with
config.file_watcher = ActiveSupport::FileUpdateChecker

And for the beginners, my current favorite way to onboard people on rails is docker. The development setup is just too complicated already.

(edit) Where is the WTF? The WTF is, that I can’t seem to be able to get this homogeneous across all the projects I touch.

3 Likes

This sort of information would be super helpful to have in the Guides.

My internet history is full of attempts to understand the “best” way to approach building a Docker container for a Rails application, and the information that’s out there is primarily opinion-based (or doesn’t cover a full production deployment, or overcomplicates matters, or promises a part 2 that never materialised).

It’d be great to get a clear example of exactly what steps are required for this, what you might need to consider, what caveats there are. To be honest, the Guides are a little lacking for good information about deployment in general, so perhaps we could use this opportunity to expand them to cover all of the possible options - Capistrano, Heroku, Docker… others?

5 Likes

When there is overwhelming complexity —> this screams volumes that a tool is necessary. What that tool is, and how it will look like - I cannot say.

I do have a vague idea: I want to develop seamlessly + deploy to production seamlessly + protect my secrets (and to check encrypted secrets into production), and I would not want to see a repeat of Webpacker 2.0 (the docker / docker-compose edition). The last thing anyone would want is to spend a few days every month working out some yml configuration, or why docker aint working.

I hope the community writes such a tool.