Skip to content

Commit

Permalink
Remove package litter after each install to shrink layer sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed May 11, 2024
1 parent 990432f commit a37f150
Showing 1 changed file with 4 additions and 5 deletions.
Expand Up @@ -12,7 +12,8 @@ WORKDIR /rails

# Install base packages
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y <%= dockerfile_base_packages.join(" ") %>
apt-get install --no-install-recommends -y <%= dockerfile_base_packages.join(" ") %> && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Set production environment
ENV RAILS_ENV="production" \
Expand All @@ -24,7 +25,8 @@ ENV RAILS_ENV="production" \
FROM base as build

# Install packages needed to build gems<%= using_node? ? " and node modules" : "" %>
RUN apt-get install --no-install-recommends -y <%= dockerfile_build_packages.join(" ") %>
RUN apt-get install --no-install-recommends -y <%= dockerfile_build_packages.join(" ") %> && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

<% if using_node? -%>
# Install JavaScript dependencies
Expand Down Expand Up @@ -88,9 +90,6 @@ RUN rm -rf node_modules
# Final stage for app image
FROM base

# Clean up installation packages to reduce image size
RUN rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
COPY --from=build /rails /rails
Expand Down

0 comments on commit a37f150

Please sign in to comment.