Deploying Rails app using Docker and Capistrano

Deploying a Rails app using Docker and Capistrano on a remote server

Solution Overview

Remote server:
* Docker container with Passenger
* Data volume (directory on the remote host) to store files for the app

* Directory structure in data volume (directory /data/apps/app1):

Capistrano-style directory structure
* current -> link to current release
* releases
* |__ release1
* |__ release2
* repo
* shared
* …

* Store files outside of container

The dynamic parts like data directories and log files remain outside on the host machine.
Docker containers are designed to be portable and immutable: you can install libraries, databases, servers.

Docker container

We will use this Docker container – https://github.com/maxivak/docker-app-rails.

It consists of Nginx+Passenger, Ruby 2.1 or 2.2.

Create Docker container

* Build image

cd config/docker

sudo docker build -t myapp1 .

It will build an image named ‘myapp1’

Run container:

sudo docker run --name=mycont_app1 myapp1

Deploy

Deployment process using Capistrano:

cap production deploy

* from Docker container: script copies files to data volume to ./releases folder

Handling shared files

* Some files can be changed on the server and we want to keep that files.
For example, images uploaded to the site should be kept on the server after deploying new version of the app.