Skip to main content

DL3042: Avoid use of cache directory with pip

Warning Efficiency

Why This Matters

By default, pip caches downloaded packages in ~/.cache/pip to speed up future installs. Inside a Docker build, this cache is never reused but it remains in the image layer, wasting 50-200 MB depending on the packages. That is dead weight that bloats your image and slows down every container pull. Use --no-cache-dir to skip caching.

How to Fix

Add --no-cache-dir to pip install

Before (incorrect)

RUN pip install flask requests

After (correct)

RUN pip install --no-cache-dir flask requests

Rule Details

Rule Code
DL3042
Severity
Warning
Category
Efficiency

Related Rules