Skip to content

Commit bbc1a1f

Browse files
authored
feat : 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 <rajpratik71@gmail.com>
1 parent e895272 commit bbc1a1f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ RUN true \
6868
&& virtualenv -p python3 /opt/graphite \
6969
&& . /opt/graphite/bin/activate \
7070
&& echo 'INPUT ( libldap.so )' > /usr/lib/libldap_r.so \
71-
&& pip install \
71+
&& pip install --no-cache-dir \
7272
cairocffi==1.1.0 \
7373
django==4.2.15 \
7474
django-tagging==0.5.0 \
@@ -94,6 +94,7 @@ ARG whisper_repo=https://github.com/graphite-project/whisper.git
9494
RUN git clone -b ${whisper_version} --depth 1 ${whisper_repo} /usr/local/src/whisper \
9595
&& cd /usr/local/src/whisper \
9696
&& . /opt/graphite/bin/activate \
97+
&& pip3 install --no-cache-dir -r requirements.txt \
9798
&& python3 ./setup.py install $python_extra_flags
9899

99100
# install carbon
@@ -103,7 +104,7 @@ ARG carbon_repo=https://github.com/graphite-project/carbon.git
103104
RUN . /opt/graphite/bin/activate \
104105
&& git clone -b ${carbon_version} --depth 1 ${carbon_repo} /usr/local/src/carbon \
105106
&& cd /usr/local/src/carbon \
106-
&& pip3 install -r requirements.txt \
107+
&& pip3 install --no-cache-dir -r requirements.txt \
107108
&& python3 ./setup.py install $python_extra_flags
108109

109110
# install graphite
@@ -113,7 +114,7 @@ ARG graphite_repo=https://github.com/graphite-project/graphite-web.git
113114
RUN . /opt/graphite/bin/activate \
114115
&& git clone -b ${graphite_version} --depth 1 ${graphite_repo} /usr/local/src/graphite-web \
115116
&& cd /usr/local/src/graphite-web \
116-
&& pip3 install -r requirements.txt \
117+
&& pip3 install --no-cache-dir -r requirements.txt \
117118
&& python3 ./setup.py install $python_extra_flags
118119

119120
# install statsd

0 commit comments

Comments
 (0)