How to Dockerize Your Rails App

March 28, 2016

This is a guideline for how to dockerize your Rails application with Puma and NGINX from your application’s git link.

What this tutorial is trying to achieve is creating two seperate container -one for your app and another for its database-. The diagram below explains the interaction between them.

Container Interaction Diagram

Build Your Own Image and Run Your Containers

I created a Docker image builder repo which helps you to build your application’s own docker image. Just follow the steps below:


  • Install Docker to your server ( I will be referring the server as docker host for the rest of the tutorial.
  • I used Ubuntu 14.04 as my docker host’s OS. Although it is possible the follow the steps to containerize your application, there might be slight differences in bash commands given below.

Create Database Container

  • Run your database container. The command below will run official postgres image as your database.

You can feel free to use other databases as your container. However, do not forget them to link them to your application container.

Create Application Container

  • Create a folder for your build materials.
  • Clone Decauville repo into your brand new folder.
git clone .
  • To build your image, fill the words in bold according to your needs and execute the command below. This may take 20 minutes, go take some coffee.
  • Upon building the image, run your application by executing command below.
docker run -d --name APPLICATION_CONTAINER_NAME -p 80:80 --link DATABASE_CONTAINER_NAME decauville:latest

If you want to share a folder from your docker host with your application execute this:


And that’s it. If you are lucky enough and your app does not have any uncommon package dependencies, your app is ready to rock.

If you still feel that you don’t understand the process entirely, you can check out build and run script for my application.


During image building, it is possible to encounter some problems. Docker will inform you about at which step in Dockerfile failure occurs. Do not hesitate to modify Dockerfile. Just comment out the lines below the last successful step and build your image. To open up a bash terminal in your pre-built container, execute the command below.

docker run -it decauville:latest /bin/bash

In your container, try to execute the failing Dockerfile command manually. Don’t be reluctant to ask me questions and do not forget: Google is your best friend.

If you can find the reason why your image fails to build, and you can solve it just by editing the existing Dockerfile, please fork the Decauville project on the github.


The Decauville project contains configuration files for puma and NGINX. You can configure them for your requirements before building your application image.

Moreover, at your container startup, is called to run your web servers. You can add additional steps to the script to execute the commands which is required by your application.