Skip to content

Instantly share code, notes, and snippets.

@farisshajahan
Created April 30, 2020 08:43
Show Gist options
  • Save farisshajahan/ccf98259e921520b6b759b9d4063723c to your computer and use it in GitHub Desktop.
Save farisshajahan/ccf98259e921520b6b759b9d4063723c to your computer and use it in GitHub Desktop.
Multistage Dockerfile for rails projects
FROM ruby:2.7.0-alpine as builder
RUN apk add \
build-base \
curl \
ca-certificates \
gnupg1 \
libffi-dev \
graphicsmagick \
libsodium-dev \
python \
make \
nodejs=12.15.0-r1 \
postgresql-dev \
tzdata \
yarn
WORKDIR /app
COPY Gemfile Gemfile.lock /app/
RUN bundle config --global frozen 1 \
&& bundle install --without development test -j4 --retry 3 \
&& rm -rf /usr/local/bundle/cache/*.gem \
&& find /usr/local/bundle/gems/ -name "*.c" -delete \
&& find /usr/local/bundle/gems/ -name "*.o" -delete
COPY . /app/
RUN SECRET_KEY_BASE='dummy' RAILS_ENV='production' bundle exec rails assets:precompile
RUN rm -rf node_modules tmp/* log/*
FROM ruby:2.7.0-alpine
RUN apk add --update --no-cache \
postgresql-dev \
graphicsmagick \
tzdata \
nodejs \
file
COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
COPY --from=builder /app/ /app/
WORKDIR /app
EXPOSE 3000
# CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0", "-p", "3000"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment