[GH-ISSUE #753] Optimization: Slice away layer build-time bloat by cleaning package caches in Dockerfiles #17594

Closed
opened 2026-07-12 18:51:13 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @BiosSystem on GitHub (May 30, 2026).
Original GitHub issue: https://github.com/docker/awesome-compose/issues/753

Problem Description

Several example Dockerfiles install packages using standard package managers (like apt or apk) but do not clean up the package manager cache and list files afterwards. This leaves unnecessary temporary files in the image layers, leading to container image bloat and slow pull/deployment times. Hadolint and Docker optimization guides recommend cleaning up lists and caches in the same RUN command where installation occurs.

Affected Examples

  1. spring-postgres (spring-postgres/backend/Dockerfile)
    • At line 14: Runs apt-get install -y --no-install-recommends git but does not clean up the /var/lib/apt/lists/* cache directory.
  2. wasmedge-kafka-mysql (wasmedge-kafka-mysql/etl/Dockerfile)
    • At line 5: Runs apt-get update && apt-get install -y git clang without cleaning up the apt lists.
  3. wasmedge-mysql-nginx (wasmedge-mysql-nginx/backend/Dockerfile)
    • Runs apt-get install without directory cleanup.

Proposed Remediations

Add cache and lists cleanup to the package installation commands:
For apt-get based images:

RUN apt-get update && apt-get install -y --no-install-recommends \
    git \
    clang \
    && rm -rf /var/lib/apt/lists/*

For apk based images, use --no-cache:

RUN apk add --no-cache git
Originally created by @BiosSystem on GitHub (May 30, 2026). Original GitHub issue: https://github.com/docker/awesome-compose/issues/753 ### Problem Description Several example Dockerfiles install packages using standard package managers (like `apt` or `apk`) but do not clean up the package manager cache and list files afterwards. This leaves unnecessary temporary files in the image layers, leading to container image bloat and slow pull/deployment times. Hadolint and Docker optimization guides recommend cleaning up lists and caches in the same `RUN` command where installation occurs. ### Affected Examples 1. **`spring-postgres`** (`spring-postgres/backend/Dockerfile`) - At line 14: Runs `apt-get install -y --no-install-recommends git` but does not clean up the `/var/lib/apt/lists/*` cache directory. 2. **`wasmedge-kafka-mysql`** (`wasmedge-kafka-mysql/etl/Dockerfile`) - At line 5: Runs `apt-get update && apt-get install -y git clang` without cleaning up the apt lists. 3. **`wasmedge-mysql-nginx`** (`wasmedge-mysql-nginx/backend/Dockerfile`) - Runs `apt-get install` without directory cleanup. ### Proposed Remediations Add cache and lists cleanup to the package installation commands: For `apt-get` based images: ```dockerfile RUN apt-get update && apt-get install -y --no-install-recommends \ git \ clang \ && rm -rf /var/lib/apt/lists/* ``` For `apk` based images, use `--no-cache`: ```dockerfile RUN apk add --no-cache git ```
Author
Owner

@BiosSystem commented on GitHub (May 30, 2026):

Closing as this issue targets example files.

<!-- gh-comment-id:4582562241 --> @BiosSystem commented on GitHub (May 30, 2026): Closing as this issue targets example files.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/awesome-compose#17594