Skip to content

Commit 14c0d73

Browse files
authored
feat : use --no-cache-dir flag to pip in dockerfiles to save space (#2357)
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 <[email protected]>
1 parent 3b4b261 commit 14c0d73

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

extra/docker/base/Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ RUN apt-get update \
4040
patchelf \
4141
&& locale-gen en_US.UTF-8 \
4242
&& update-locale LANG=en_US.UTF-8 \
43-
&& PYTHONPATH=`echo /usr/share/python-wheels/pip-*.whl` python2.7 -m pip install --upgrade pip setuptools wheel \
44-
&& python2.7 -m pip install --upgrade pwntools \
45-
&& python3 -m pip install --upgrade pip \
46-
&& python3 -m pip install --upgrade pwntools \
43+
&& PYTHONPATH=`echo /usr/share/python-wheels/pip-*.whl` python2.7 -m pip install --no-cache-dir --upgrade pip setuptools wheel \
44+
&& python2.7 -m pip install --no-cache-dir --upgrade pwntools \
45+
&& python3 -m pip install --no-cache-dir --upgrade pip \
46+
&& python3 -m pip install --no-cache-dir --upgrade pwntools \
4747
&& PWNLIB_NOTERM=1 pwn update \
4848
&& useradd -m pwntools \
4949
&& passwd --delete --unlock pwntools \

extra/docker/beta/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM pwntools/pwntools:stable
22

33
USER root
4-
RUN python2.7 -m pip install --upgrade git+https://github.com/Gallopsled/pwntools@beta \
5-
&& python3 -m pip install --force-reinstall --upgrade git+https://github.com/Gallopsled/pwntools@beta
4+
RUN python2.7 -m pip install --no-cache-dir --upgrade git+https://github.com/Gallopsled/pwntools@beta \
5+
&& python3 -m pip install --no-cache-dir --force-reinstall --upgrade git+https://github.com/Gallopsled/pwntools@beta
66
RUN PWNLIB_NOTERM=1 pwn update
77
USER pwntools

extra/docker/buster/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ RUN apt-get -y dist-upgrade
55
RUN apt-get -y install python3 python3-pip
66
RUN apt-get -y install git wget unzip
77

8-
RUN pip3 install --upgrade git+https://github.com/Gallopsled/pwntools@dev
8+
RUN pip3 install --no-cache-dir --upgrade git+https://github.com/Gallopsled/pwntools@dev

extra/docker/stable/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM pwntools/pwntools:base
22

33
USER root
4-
RUN python2.7 -m pip install --upgrade git+https://github.com/Gallopsled/pwntools@stable \
5-
&& python3 -m pip install --force-reinstall --upgrade git+https://github.com/Gallopsled/pwntools@stable
4+
RUN python2.7 -m pip install --no-cache-dir --upgrade git+https://github.com/Gallopsled/pwntools@stable \
5+
&& python3 -m pip install --no-cache-dir --force-reinstall --upgrade git+https://github.com/Gallopsled/pwntools@stable
66
RUN PWNLIB_NOTERM=1 pwn update
77
USER pwntools

travis/docker/Dockerfile

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ ENV PATH="/home/pwntools/.local/bin:${PATH}"
1818

1919
# Install Pwntools to the home directory, make it an editable install
2020
RUN git clone https://github.com/Gallopsled/pwntools \
21-
&& python2.7 -m pip install --upgrade --editable pwntools \
22-
&& python3 -m pip install --upgrade --editable pwntools \
21+
&& python2.7 -m pip install --no-cache-dir --upgrade --editable pwntools \
22+
&& python3 -m pip install --no-cache-dir --upgrade --editable pwntools \
2323
&& PWNLIB_NOTERM=1 pwn version
2424

2525
# Requirements for running the tests
26-
RUN python2.7 -m pip install --upgrade --requirement pwntools/docs/requirements.txt \
27-
&& python3 -m pip install --upgrade --requirement pwntools/docs/requirements.txt
26+
RUN python2.7 -m pip install --no-cache-dir --upgrade --requirement pwntools/docs/requirements.txt \
27+
&& python3 -m pip install --no-cache-dir --upgrade --requirement pwntools/docs/requirements.txt
2828

2929
# Python niceties for debugging
30-
RUN python2.7 -m pip install -U ipython ipdb \
31-
&& python3 -m pip install -U ipython ipdb
30+
RUN python2.7 -m pip install --no-cache-dir -U ipython ipdb \
31+
&& python3 -m pip install --no-cache-dir -U ipython ipdb
3232

3333
# Dependencies from .travis.yml addons -> apt -> packages
3434
ARG DEBIAN_FRONTEND=noninteractive
@@ -86,8 +86,8 @@ ADD ipython_config.py /home/pwntools/.ipython/profile_default
8686
RUN echo "pwntools ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/travis
8787

8888
# Some additional debugging tools that are useful
89-
RUN python2.7 -m pip install ipdb && \
90-
python3 -m pip install ipdb
89+
RUN python2.7 -m pip install --no-cache-dir ipdb && \
90+
python3 -m pip install --no-cache-dir ipdb
9191

9292
# Install debugging utilities
9393
USER root

travis/docker/Dockerfile.travis

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Some additional debugging tools that are useful
3-
RUN python2.7 -m pip install ipdb && \
4-
python3 -m pip install ipdb
3+
RUN python2.7 -m pip install --no-cache-dir ipdb && \
4+
python3 -m pip install --no-cache-dir ipdb
55

66
# Install debugging utilities
77
USER root

0 commit comments

Comments
 (0)