Skip to content

Instantly share code, notes, and snippets.

@robjacoby
Last active September 8, 2015 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robjacoby/fc2aa0a4a924474f7cf1 to your computer and use it in GitHub Desktop.
Save robjacoby/fc2aa0a4a924474f7cf1 to your computer and use it in GitHub Desktop.
Ruby/Rails Dockerfiles
# ---------------------------------------------------------------------------
# This is the Dockerfile to build the base image for ruby/rails/mysql
# ---------------------------------------------------------------------------
FROM debian:jessie
MAINTAINER XXX
ENV REFRESHED_AT 2015-08-07
# ---------------------------------------------------------------------------
# Using ruby-2.2.0
# ---------------------------------------------------------------------------
ENV RUBY_MAJOR 2.2
ENV RUBY_VERSION 2.2.0
# ---------------------------------------------------------------------------
# System and Ruby dependencies
# ---------------------------------------------------------------------------
ENV SYS_DEPS git curl procps autoconf build-essential libbz2-dev libcurl4-openssl-dev libffi-dev libssl-dev libreadline-dev libyaml-dev zlib1g-dev
ENV RUBY_DEPS bison ruby libmysqlclient-dev
# ---------------------------------------------------------------------------
# Install all dependencies, compile ruby and cleanup
# ---------------------------------------------------------------------------
RUN apt-get update \
&& apt-get install -y --no-install-recommends ${SYS_DEPS} ${RUBY_DEPS} \
&& mkdir -p /usr/src/ruby \
&& curl -SL "http://cache.ruby-lang.org/pub/ruby/$RUBY_MAJOR/ruby-$RUBY_VERSION.tar.bz2" | tar -xjC /usr/src/ruby --strip-components=1 \
&& cd /usr/src/ruby \
&& autoconf \
&& ./configure --disable-install-doc \
&& make -j"$(nproc)" \
&& apt-get purge -y --auto-remove bison ruby \
&& make install \
&& rm -r /usr/src/ruby \
&& rm -rf /var/lib/apt/lists/*
# ---------------------------------------------------------------------------
# Ensure timezone is present
# ---------------------------------------------------------------------------
RUN echo Australia/Brisbane > /etc/timezone && dpkg-reconfigure --frontend noninteractive tzdata
# ---------------------------------------------------------------------------
# Skip installing gem documentation
# ---------------------------------------------------------------------------
RUN echo 'gem: --no-rdoc --no-ri' >> "$HOME/.gemrc"
# ---------------------------------------------------------------------------
# Set the gem home, install bundler and configure it
# ---------------------------------------------------------------------------
ENV GEM_HOME /usr/local/bundle
ENV PATH $GEM_HOME/bin:$PATH
RUN gem update --system \
&& gem install bundler \
&& bundle config --global path "$GEM_HOME" \
&& bundle config --global bin "$GEM_HOME/bin" \
&& gem install foreman
# ---------------------------------------------------------------------------
# Don't create ".bundle" in all our apps
# ---------------------------------------------------------------------------
ENV BUNDLE_APP_CONFIG $GEM_HOME
# ---------------------------------------------------------------------------
# This is the Dockerfile to build the prod app image
# ---------------------------------------------------------------------------
FROM 10.150.0.21:5000/base_images/rails:latest
MAINTAINER XXX
ENV REFRESHED_AT 2015-08-07
ENV HOME /app
WORKDIR /tmp
ADD Gemfile Gemfile
ADD Gemfile.lock Gemfile.lock
RUN gem install bundler
RUN bundle install -j4 --without development test --retry 3
ADD . /app
WORKDIR /app
RUN rm -rf /tmp/*
EXPOSE 5000
CMD ["bundle", "exec", "foreman", "start"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment