Skip to content

Commit d539810

Browse files
authored
Remove package litter after each install to shrink layer sizes (rails#51792)
* Remove package litter after each install to shrink layer sizes * Need a refresh on the index when the cache is gone
1 parent 3af5c07 commit d539810

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

railties/lib/rails/generators/rails/app/templates/Dockerfile.tt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ WORKDIR /rails
1212

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

1718
# Set production environment
1819
ENV RAILS_ENV="production" \
@@ -24,7 +25,9 @@ ENV RAILS_ENV="production" \
2425
FROM base as build
2526

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

2932
<% if using_node? -%>
3033
# Install JavaScript dependencies
@@ -88,9 +91,6 @@ RUN rm -rf node_modules
8891
# Final stage for app image
8992
FROM base
9093

91-
# Clean up installation packages to reduce image size
92-
RUN rm -rf /var/lib/apt/lists /var/cache/apt/archives
93-
9494
# Copy built artifacts: gems, application
9595
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
9696
COPY --from=build /rails /rails

0 commit comments

Comments
 (0)