Skip to content

Instantly share code, notes, and snippets.

@Florian95
Created September 14, 2016 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Florian95/d1a1a5087baef794a26b0de784468c29 to your computer and use it in GitHub Desktop.
Save Florian95/d1a1a5087baef794a26b0de784468c29 to your computer and use it in GitHub Desktop.
Rails Web application on Docker Debian
FROM debian:8.5
## Image metadata ##
MAINTAINER Stuart Ellis, stuart@stuartellis.eu
LABEL description="Rails Web application on Debian"
## Application user account ##
ENV APP_USER app
RUN useradd -d /home/$APP_USER -m $APP_USER && \
chown -R $APP_USER:$APP_USER /home/$APP_USER
## Debian packages ##
# App dependencies first, so that they are not uninstalled by autoremove:
# * The Nokogiri gem requires libxml2
# * Ruby on Rails requires Node.js for asset compilation
# * Rails applications may use Ghostscript, Imagemagick and the MySQL client
ENV APP_DEPS ca-certificates ghostscript imagemagick monit sudo \
libxml2 libxslt1.1 libyaml-0-2 \
mysql-client nodejs openssl
RUN apt-get update && apt-get install -y --no-install-recommends $APP_DEPS
ENV BUILD_DEPS autoconf automake bison libtool make g++ \
bzip2 curl git sqlite3 \
libcurl4-openssl-dev libffi-dev libgdbm-dev \
libmagickcore-dev libmagickwand-dev libmysqlclient-dev libncurses5-dev \
libreadline-dev libsqlite3-dev libssl-dev libxml2-dev libxslt1-dev \
libyaml-dev zlib1g-dev
RUN apt-get install -y --no-install-recommends $BUILD_DEPS && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
## Install Ruby ##
ENV RUBY_VERSION 2.3.1
### Install ruby-build ###
RUN git clone https://github.com/rbenv/ruby-build.git /tmp/ruby-build --depth 1 && \
cd /tmp/ruby-build && \
./install.sh && \
cd / && \
rm -rf /tmp/ruby-build
### Install Ruby using ruby-build ###
# Setting to disable generation of Ruby documentation with ruby-build
ENV CONFIGURE_OPTS --disable-install-rdoc
RUN ruby-build -v $RUBY_VERSION /usr/local
RUN gem install bundler --without development --no-rdoc --no-ri
## Monit configuration ##
COPY bin/delayed_job_srv /etc/init.d/
COPY ["config/monit/delayed_job.conf", "config/monit/monit_http.conf", "/etc/monit/conf.d/"]
COPY config/monit/monit_sudo /etc/sudoers.d/
RUN chown -R root:root /etc/init.d/delayed_job_srv && \
chmod 0755 /etc/init.d/delayed_job_srv && \
chown -R root:root /etc/monit/conf.d/delayed_job.conf && \
chmod 0644 /etc/monit/conf.d/delayed_job.conf && \
chown -R root:root /etc/monit/conf.d/monit_http.conf && \
chmod 0644 /etc/monit/conf.d/monit_http.conf && \
chown -R root:root /etc/sudoers.d/monit_sudo && \
chmod 0440 /etc/sudoers.d/monit_sudo
## Application ##
### Set up a working directory inside the image ###
ENV APP_HOME /usr/src/app
RUN mkdir $APP_HOME && chown -R $APP_USER:$APP_USER $APP_HOME
### Use the application working directory ###
WORKDIR $APP_HOME
### Install gem packages for the application ###
COPY Gemfile* $APP_HOME/
RUN bundle config build.nokogiri --use-system-libraries && \
bundle install --deployment --without development
### Populate the application working directory ###
COPY . $APP_HOME
RUN chown -R $APP_USER:$APP_USER $APP_HOME
# Switch to the unprivileged user account
USER $APP_USER
### Pre-compile the assets for the application ###
RUN bin/rake assets:precompile
## Container default settings ##
EXPOSE 3000 5627
CMD ["bin/docker_cmd"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment