It's 2023. Cars are flying fuelled by water, tourists visiting outer space, and I'm still not sure how to best deploy my personal project apps.
Heroku got somewhat lame. Other managed platforms are not the same as Heroku was before. I'm too lazy to self-host and self-maintain...
At the same time, I collaborate with people in some of my projects who are just waiting to crush my dreams of moving fast with Ruby on Rails. With their funny Ubuntu setup for example. Or Windows.
Docker could help unify the setup. Wrapping everything in some bin/do
commands could make the setup a breeze.
Depending on where you are on the journey, you have a couple of options. I'm not yet seeing the best way to dockerize a Rails app, so you will need to make the judging call yourself. For now, I'll provide you with ideas and resources.
Disclaimer for Rails beginners
As a total beginner, you might benefit from not dockerizing your app at all. It has a learning curve and you might not benefit much from it as long as you don't have to jump a lot between different projects and OS setups or don't have a project where a lot of developers jump into it needing a quick setup.
If you still would like to dig into it, start with the fundamentals and learn about Docker itself, then go into the Rails-specific details. Some of the below resources might help.
Ways to put your Rails app into Docker
There are millions.
If you are a seasoned developer and infrastructure friend: I found it useful to read through a couple of blog posts and book sections. Then read their relevant files, approximately in that order:
Dockerfile
docker-compose.yml
bin/
folder
While I was digging the resources below, I also installed Docker and started to play around with some of them.
This way I got a pretty nice overview of the dockerizing Rails apps with that approach.
Problems
Common problems you'll often encounter with dockerizing:
- non-automated docker files generation (leading to inconsistencies in the setup)
- not addressing common gems that need installing
- needing another type of dependency, like you need an extra Ruby gem on your local to manage the docker service (see first article in resources)
Resources
These are resources that I've read through, that order will give you the basics, and by arriving at the latter resources you will already have a good basis:
- evil martians deep dive with additional gem
- another deep dive
- super-duper automated sustainable Rails docker
- one more deep dive to mix it up, written by a bash god
- Approach that's now in included in Rails 7 itself
- Rails 7 without JS docker setup
- how fly.io does it (without docker compose file)
One other resource that looks promising but I haven't tried yet that shows it all in a container:
There are also books written about it:
However, I don't know anything about them yet. Let me know if you do :))
In the end, the approaches I liked the most were:
They worked well for a dummy project but I have yet to try them in a production-like environment, but they make a good first impression because they are:
- fairly automated
- enough for running a functional Rails app
- does not need any dependencies on your operating system other than Docker