Skip to content

Instantly share code, notes, and snippets.

@RoyalIcing
Last active April 2, 2020 17:06
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save RoyalIcing/2897c0b0e15a777391e20881b066e8f3 to your computer and use it in GitHub Desktop.
Save RoyalIcing/2897c0b0e15a777391e20881b066e8f3 to your computer and use it in GitHub Desktop.
Rails 5.1 Dockerfile
FROM ruby:2.4-alpine
ENV PATH /root/.yarn/bin:$PATH
RUN apk update && apk upgrade && \
apk add --no-cache bash git openssh build-base nodejs tzdata
RUN apk update \
&& apk add curl bash binutils tar gnupg \
&& rm -rf /var/cache/apk/* \
&& /bin/bash \
&& touch ~/.bashrc \
&& curl -o- -L https://yarnpkg.com/install.sh | bash \
&& apk del curl tar binutils
# Configure the main working directory. This is the base
# directory used in any further RUN, COPY, and ENTRYPOINT
# commands.
WORKDIR /usr/src/app
# Copy the Gemfile as well as the Gemfile.lock and install
# the RubyGems. This is a separate step so the dependencies
# will be cached unless changes to one of those two files
# are made.
COPY Gemfile Gemfile.lock ./
RUN gem install bundler && bundle install -j "$(getconf _NPROCESSORS_ONLN)" --retry 5 --without development test
# Copy dependencies for Node.js and instance the packages.
# Again, being separate means this will cache.
COPY package.json yarn.lock ./
RUN yarn install
RUN npm rebuild node-sass --force
# Set Rails to run in production
ENV RAILS_ENV production
ENV RACK_ENV production
ENV RAILS_ROOT /usr/src/app
# Use Rails for static files in public
ENV RAILS_SERVE_STATIC_FILES 1
# You must pass environment variable SECRET_KEY_BASE
ARG SECRET_KEY_BASE
ENV SECRET_KEY_BASE $SECRET_KEY_BASE
# Copy the main application.
COPY . ./
# Precompile Rails assets (plus Webpack)
RUN bundle exec rake assets:precompile
# Will run on port 3000 by default
EXPOSE 3000
# Start puma
CMD bundle exec puma -C config/puma.rb
@tmaier
Copy link

tmaier commented Jun 18, 2017

Consider to use -j "$(getconf _NPROCESSORS_ONLN)" instead of --jobs 20

@PabloC
Copy link

PabloC commented Jan 21, 2019

thanks for this!

@monogot
Copy link

monogot commented Mar 18, 2019

You saved my life!

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