I’ve got a bunch of Rails apps, but only a handful of cloud servers. I need some of them to live on a single machine without them stepping all over each other.
This guide assumes the server is running Ubuntu 14.04 and has all the requisite software already installed (e.g.: Docker, Rails, etc.).
Docker makes the following configuration easy to maintain:
Docker is also nice because all the required containers come pre-packaged:
You’ll need one for each Rails app you wish to deploy. These can be self-signed or obtained from a Certificate Authority. To self-sign a certificate, execute the following:
out options. The
jwilder/nginx-proxy Docker image won’t pick up the certificates unless they are named in accordance with the production site’s URL and subdomain (if any). For example, if you have a certificate for
example.com, the keyout and out options must be named
Obtain a certificate for each app you wish to deploy (or just get one for the purposes of this tutorial).
Note the app username. Adjust as appropriate.
Now for the tricky part…
This configuration is meant to make deployment easy. The easiest way I’ve discovered so far involves writing a
Dockerfile for the Rails app and providing Nginx some configuration files.
Save this sample
Dockerfile in your app’s root directory on the server (next to the
ADD commands under the Configure Nginx header. These are copying configurations into the Docker image. Here I put them in the
docker directory to keep them organized. From your app’s root directory:
Now, save the following to
Of course, change the server name as appropriate. Also note the
/home/app directory. app is the username set up by the
Next, save the following to
This is some Docker magic that preserves these Postgres environment variables.
Now, build the app’s image from the project’s root directory:
This command reads the
Dockerfile just created and executes the instructions contained therein.
Setup, migrate, and seed the database:
Finally, execute the image:
If everything goes well, you will be able to see your app at example.com (or wherever).