Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Dockerfile example for a Rails app
# Select ubuntu as the base image
FROM ruby:2.2.0
# see for why all "apt-get install"s have to stay as one long line
RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/*
# see
RUN apt-get update && apt-get install -qy postgresql-client sqlite3 imagemagick libmagickwand-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN gem install rails --version "$RAILS_VERSION"
MAINTAINER Michelangelo Chasseur <>
# Create directory from where the code will run
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Make unicorn reachable to other containers
# Set ENV variables
# Container should behave like a standalone executable
CMD ["foreman","start"]
# Install the necessary gems
ADD Gemfile /usr/src/app/Gemfile
ADD Gemfile.lock /usr/src/app/Gemfile.lock
RUN bundle install --without development test
# Add rails project (from same dir as Dockerfile) to project directory
ADD ./ /usr/src/app
# Run rake tasks
RUN RAILS_ENV=production rake db:create db:migrate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.