Ensure use '--no-cache-dir' in pip install

--no-cache-dir flag removes unneeded files that take storage space and affect your final image size. The size reduction can be surprisingly significant.

Risk Level: medium
Platform: Docker
Spectral Rule ID: DOCKR038

REMEDIATION

Append each pip install with --no-cache-dir.

FROM python:3
- RUN pip install --upgrade pip && \
-   pip install nibabel pydicom matplotlib pillow && \
-   pip install med2image
+ RUN pip install --no-cache-dir --upgrade pip && \
+   pip install --no-cache-dir nibabel pydicom matplotlib pillow && \
+   pip install --no-cache-dir med2image
RUN pip3 install --no-cache-dir requests=2.7.0
- RUN ["pip3", "install", "requests=2.7.0"]
+ RUN ["pip3", "install", "requests=2.7.0", "--no-cache-dir"]
CMD ["cat", "/etc/os-release"]

Read more: