Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dockerfile example for a Rails app
# Select ubuntu as the base image
FROM ruby:2.2.0
# see update.sh 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 http://guides.rubyonrails.org/command_line.html#rails-dbconsole
RUN apt-get update && apt-get install -qy postgresql-client sqlite3 imagemagick libmagickwand-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV RAILS_VERSION 4.1.1
RUN gem install rails --version "$RAILS_VERSION"
MAINTAINER Michelangelo Chasseur <michelangelo.chasseur@touchwa.re>
# Create directory from where the code will run
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Make unicorn reachable to other containers
EXPOSE 3000
# Set ENV variables
ENV PORT=3000
# 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.