From 1427848e5ea7a6011b7ea3da5e83c87bad591781 Mon Sep 17 00:00:00 2001 From: Pratik Raj Date: Thu, 11 Aug 2022 13:28:54 +0530 Subject: [PATCH] use `--no-cache-dir` flag to `pip` in dockerfiles to save space using the "--no-cache-dir" flag in pip install, make sure downloaded packages by pip don't cache on the system. This is a best practice that makes sure to fetch from a repo instead of using a local cached one. Further, in the case of Docker Containers, by restricting caching, we can reduce image size. In terms of stats, it depends upon the number of python packages multiplied by their respective size. e.g for heavy packages with a lot of dependencies it reduces a lot by don't cache pip packages. Further, more detailed information can be found at https://medium.com/sciforce/strategies-of-docker-images-optimization-2ca9cc5719b6 Signed-off-by: Pratik Raj --- Dockerfile | 2 +- Dockerfiles/ci/Dockerfile | 2 +- upstream/roles/install_iib/templates/Dockerfile-workers.j2 | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 83f9d3533..73302ec3f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM fedora:33 RUN dnf install -y git podman buildah python3-libselinux python3-pip -RUN pip3 install ansible==2.10.5 jmespath +RUN pip3 install --no-cache-dir ansible==2.10.5 jmespath RUN mkdir -p /playbooks COPY roles/ /playbooks/roles/ COPY filter_plugins/ /playbooks/filter_plugins/ diff --git a/Dockerfiles/ci/Dockerfile b/Dockerfiles/ci/Dockerfile index 770f3f580..95a0d5469 100644 --- a/Dockerfiles/ci/Dockerfile +++ b/Dockerfiles/ci/Dockerfile @@ -13,6 +13,6 @@ RUN export ARCH=$(case $(arch) in x86_64) echo -n amd64 ;; aarch64) echo -n arm6 mkdir /project/output && \ dnf install --setopt=install_weak_deps=False -y git-core ansible python3-pip mlocate jq skopeo && \ dnf clean all && \ - pip3 install operator-courier + pip3 install --no-cache-dir operator-courier ADD ./run_tests.py /run_tests.py CMD ["/run_tests.py"] diff --git a/upstream/roles/install_iib/templates/Dockerfile-workers.j2 b/upstream/roles/install_iib/templates/Dockerfile-workers.j2 index 3f3782ac1..6c76970ce 100644 --- a/upstream/roles/install_iib/templates/Dockerfile-workers.j2 +++ b/upstream/roles/install_iib/templates/Dockerfile-workers.j2 @@ -75,6 +75,6 @@ RUN sed -i -e 's|^#mount_program|mount_program|g' /etc/containers/storage.conf COPY docker/libpod.conf /usr/share/containers/libpod.conf COPY . . -RUN pip3 install -r requirements.txt --no-deps --require-hashes -RUN pip3 install . --no-deps +RUN pip3 install --no-cache-dir -r requirements.txt --no-deps --require-hashes && \ + pip3 install --no-cache-dir . --no-deps CMD ["/bin/celery-3", "-A", "iib.workers.tasks", "worker", "--loglevel=info"]