Containerizing Rails: Techniques, Pitfalls, & Best Practices
Presentation by Daniel Azuma at RailsConf 2018. Covers best practices for designing Docker images for Rails applications. More information at http://daniel-azuma.com/railsconf2018
FROM my-base AS builder COPY . /app RUN apt-get install build-essential \ && bundle install --deployment FROM my-base COPY --from=builder /app /app Ruby base image
FROM my-base AS builder COPY . /app RUN apt-get install build-essential \ && bundle install --deployment FROM my-base COPY --from=builder /app /app Ruby base image App source Compilers, etc.
FROM my-base AS builder COPY . /app RUN apt-get install build-essential \ && bundle install --deployment FROM my-base COPY --from=builder /app /app Ruby base image Ruby base image App source Vendored gems Compilers, etc.
FROM my-base AS builder COPY . /app RUN apt-get install build-essential \ && bundle install --deployment FROM my-base COPY --from=builder /app /app Ruby base image App w/vendored gems Tip #3: Use a separate build stage
"Australia in a Nutshell" (Sign contents modified) Photo by: Kristian Thøgersen Source: https://www.flickr.com/photos/flottenheimer/5534636006 License: https://creativecommons.org/licenses/by/2.0/
Tip #5: Create an unprivileged user # After building your app... RUN adduser -s /bin/sh -u 1001 -G root \ -h /app -S -D rails \ && chown -R rails /app USER rails