Skip to content

Instantly share code, notes, and snippets.

@maxivak
Last active October 7, 2017 11:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxivak/de44fb7721904a043538b5402576e0f6 to your computer and use it in GitHub Desktop.
Save maxivak/de44fb7721904a043538b5402576e0f6 to your computer and use it in GitHub Desktop.
Deploying Rails app using Docker and Capistrano

Deploying Rails app using Docker and Capistrano

Concept

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment