Most tutorials about using Docker to develop Rails apps are just plain wrong. Oh, they get you to Hello, World, but since when do you deploy that? Using that Hello, World setup will lead to frustration. It will be slow, hard to use and have you hating on Docker in no time.

We can do so much better.

What’s Wrong with other Tutorials?

Hello, World tutorials are a great way to see what a framework or system can do, but it’s not like you read a Rails Hello, World tutorial and then went out and wrote a great app. You had a lot more to learn.

Most Docker tutorials skip over how Docker works. This is understandable, it’s a complex topic. However, you need a deeper understanding if you’re going to use Docker well.

Why use Docker?

Now I don’t want to scary you off Docker. Yes, there’s things to learn, but, there’s a huge return on investment.

In my mind, there are three main advantages to using Docker in development.

  1. It contains the dependencies. Typically, I’m on two or three projects with different infrastructure regiments. I’ll also have maybe another dozen projects in maintenance mode which I may need to spin up. In the past this has meant needing to have PostgreSQL, MySQL, MongoDB, Redis, and Memcached all running locally on my Mac. With Docker (specifically Docker Compose), those dependencies can tied to the project, started and stopped as needed, and, most importantly, not installed on my Mac.
  2. It allows you to develop in an environment that is the same as production. Same version of Linux. Same version of Ruby. Same version of external apps like ImageMagick or wkhtmltopdf. That “same as production” environment means you can build and possibly even test production locally and avoid surprises on deploy.
  3. You can separate concerns. Most app development I do uses Rails for the backend API and then a Javascript framework like React, Vue, or Nuxt for the UI. Rails provides what to embed these frameworks, but it’s far easier to develop if they are separate components.

Still with me? Great, let’s move on to the details.

What is Docker? REWRITE ME. Separate post.

When people say “Docker” they mean a whole host of things (a blog post in it’s own right) but let’s keep it as simple as we can. In fact, what follows is conceptually correct, but not necessarily technically correct.

Docker is a system for building and running light weight virtual servers and networks. You can think of it as your own private cloud.

MORE NARRATIVE

A “Docker image” is a disk attached to a server. (snapshot) immutability A “Docker container” is a server launched from an image.

“docker” is a command for managing containers. “docker-compose” is a command to simplify managing multiple containers. Most of the time you will use “docker-compose” instead of “docker”.

A Dockerfile is a script like file containing instructions for building a “Docker image”.

That’s a lot to take in, but real the critical thing is images and how they are build of layers.

Comments