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
DL3014 Warning
Use the -y switch for apt-get install
DL3003 Warning
Use WORKDIR to switch directories
DL4006 Warning
Set the SHELL option -o pipefail before RUN with a pipe in
DL3059 Info
Multiple consecutive RUN instructions
DL3015 Info
Avoid additional packages by specifying --no-install-recommends