Skip to content

Instantly share code, notes, and snippets.

@gottfrois
Created September 6, 2018 08:59
Show Gist options
  • Save gottfrois/0603e33a4be0fe3c27c40ac21b636957 to your computer and use it in GitHub Desktop.
Save gottfrois/0603e33a4be0fe3c27c40ac21b636957 to your computer and use it in GitHub Desktop.
medium-multi-stage-dockerfile-runner-stage
###############################
# Stage runner
FROM ruby as runner
LABEL description="Builds an image ready to be run"
# Install runtime deps and create non-root user.
#
# If you need to install specific libraries for test environment
# please use a virtual pkg holder you can easily remove on the
# `release` stage.
#
# For example:
# RUN apk add --update --no-cache --virtual .test-deps \
# somelib-only-used-for-test
# Then in the `release` image:
# RUN apk del .test-deps
#
# - libxml2 -- used to run nokogiri
# - libxslt -- used to run nokogiri
# - nodejs -- used to compile assets
# - tzdata -- used to install TZinfo data
RUN apk add --update --no-cache \
libxml2 \
libxslt \
nodejs \
tzdata \
&& addgroup -g 1000 -S app \
&& adduser -u 1000 -S app -G app
USER app
WORKDIR /home/app
# Copy bundle config from bundler stage
COPY --chown=app:app --from=bundler /usr/local/bundle/config /usr/local/bundle/config
# Copy bundled gems from bundler stage
COPY --chown=app:app --from=bundler /home/app/vendor /home/app/vendor
# Copy source files according to .dockerignore policy
# Make sure your .dockerignore file is properly configured to ensure proper layer caching
COPY --chown=app:app . /home/app
ENV PORT 3000
# Expose web server port
EXPOSE 3000
ENTRYPOINT ["bundle", "exec"]
CMD ["puma", "-C", "config/puma.rb"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment