How Do We Run Our Rails App?

Find the best option to build our Rails app.

Ways to run our Rails app

Unfortunately, we cannot start a Rails server with just the ruby:2.7 image. Rails has a few more requirements like JavaScript interpreter (Node.js) to help with the asset pipeline and gem dependencies. One way is to run Bash inside a container based on the ruby:2.7 image, and install what we need from there. However, running the commands manually is not easily repeatable.

Another way to get a container is to run Rails by taking that same set of commands needed to install Rails’ requirements and chain them together into a long, compound docker run command. The compound docker run allows you to start a container and run a single command in docker run by using the bash command’s -c option. The -c option starts a Bash shell and immediately executes whatever you pass in as a string. This lets you do the following:

$ docker run <options> [image:version] \ 
bash -c "command1 && command2 && command3..."

However, not only would the command be huge, ugly, and hard to remember, but worst of all, it would be slow. The setup instructions would have to be run from scratch every time, including installing Node.js or our gem dependencies. We do not want to wait minutes just to start a Rails server.

So what’s the real solution?

We want to be able to run containers based on a preconfigured state that has everything needed in order to run Rails. What we really want is a factory for creating these perfect Rails server containers. And building an image is a perfect fit for our requirements.

Get hands-on with 1400+ tech skills courses.