Review apk installation cache management

Choose an installation approach that keeps unnecessary apk caches out of the final image.

Description

apk add --update-cache can leave refreshed indexes in the image.

Potential impact

Shipping the cache takes extra space. Repeated builds can still benefit from a cache stored outside the image.

Remediation

Use apk add --no-cache for the install. Check the final image for caches from earlier layers, which this option leaves in place.

Examples

For production, use a supported Alpine base and its package repositories.

Before

dockerfile
FROM alpine:3.20

RUN apk add --update-cache python3

After

dockerfile
FROM alpine:3.20

RUN apk add --no-cache python3

References