Skip to content

Instantly share code, notes, and snippets.

@rachelmyers
Last active September 20, 2016 00:30
Show Gist options
  • Save rachelmyers/6df04f541fc480f3280ca347258c83bb to your computer and use it in GitHub Desktop.
Save rachelmyers/6df04f541fc480f3280ca347258c83bb to your computer and use it in GitHub Desktop.
A basic Dockerfile for a Rails app moving off Heroku, without addons
# Our base image is Ruby 2.2; it will run on Amazon Linux.
FROM ruby:2.2
# Install packages
RUN apt-get update && apt-get install -y \
git \
nodejs \
tzdata
# Copy your application into the container.
COPY . .
# Build your application.
RUN \
# Install application gems.
bundle install --jobs 4 --without development test --with production && \
# Precompile Rails assets.
RAILS_ENV=production bundle exec rake assets:precompile && \
# Clean up build package
rm -rf /usr/local/lib/ruby/gems/*/cache/* && \
rm -rf ~/.gem
# Run your application.
CMD bin/rails server --port 3000
@rachelmyers
Copy link
Author

To move off Heroku:

  • Add the Dockerfile to the root of the application; for a plain Rails app, this will work, adjusting this for Ruby versions
  • Add a new environment to database.yml; it'll be something like this:
production:
  adapter: mysql2
  encoding: utf8
  database: <app_name>_prod
  username: root
  • Spin up new servers, on your own, or using a service; I'm partial to Opsolutely
  • Snapshot the database in Heroku, using Heroku's backup commands
  • Initialize new database instances; like Amazon's RDS or Amazon's Aurora (which has improved performance and replication)
  • When the new server and database are setup, update DNS to point traffic to the new servers
  • Decommission the old servers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment