From 6c5f27d7f126bc8cb429779db74265e69d1ea7d4 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Fri, 19 May 2023 22:01:23 +0800 Subject: [PATCH 1/2] Speed up Docker image build and make image smaller Run `apt-get upgrade` right after `apt-get install`, instead of cleaning up apt index first, do `apt-get update` again, then `apt-get upgrade`. This will save some build time and disk space, because it didn't clean up apt index after the `apt-get upgrade` before. --- docker/Dockerfile | 3 +-- docker/cuda.Dockerfile | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index a988e3d..fb4f35d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -5,11 +5,10 @@ WORKDIR /app ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update -qq \ && apt-get -qqq install --no-install-recommends -y pkg-config gcc g++ \ + && apt-get upgrade --assume-yes \ && apt-get clean \ && rm -rf /var/lib/apt -RUN apt-get update && apt-get upgrade --assume-yes - RUN python -mvenv venv && ./venv/bin/pip install --upgrade pip COPY . . diff --git a/docker/cuda.Dockerfile b/docker/cuda.Dockerfile index 0abe4f4..232f8a6 100644 --- a/docker/cuda.Dockerfile +++ b/docker/cuda.Dockerfile @@ -9,11 +9,10 @@ WORKDIR /app ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update -qq \ && apt-get -qqq install --no-install-recommends -y libicu-dev libaspell-dev libcairo2 libcairo2-dev pkg-config gcc g++ python3.8-dev python3-pip libpython3.8-dev\ + && apt-get upgrade --assume-yes \ && apt-get clean \ && rm -rf /var/lib/apt -RUN apt-get update && apt-get upgrade --assume-yes - RUN pip3 install --upgrade pip && apt-get remove python3-pip --assume-yes RUN ln -s /usr/bin/python3 /usr/bin/python From 842a2860af3bb736f15b522fb0c4d4f0aad85ce5 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Fri, 19 May 2023 22:41:14 +0800 Subject: [PATCH 2/2] Optimize pip install in Dockerfile to minimize image size --- docker/Dockerfile | 2 +- docker/cuda.Dockerfile | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index fb4f35d..4885701 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -9,7 +9,7 @@ RUN apt-get update -qq \ && apt-get clean \ && rm -rf /var/lib/apt -RUN python -mvenv venv && ./venv/bin/pip install --upgrade pip +RUN python -mvenv venv && ./venv/bin/pip install --no-cache-dir --upgrade pip COPY . . diff --git a/docker/cuda.Dockerfile b/docker/cuda.Dockerfile index 232f8a6..1b29547 100644 --- a/docker/cuda.Dockerfile +++ b/docker/cuda.Dockerfile @@ -13,17 +13,17 @@ RUN apt-get update -qq \ && apt-get clean \ && rm -rf /var/lib/apt -RUN pip3 install --upgrade pip && apt-get remove python3-pip --assume-yes +RUN pip3 install --no-cache-dir --upgrade pip && apt-get remove python3-pip --assume-yes RUN ln -s /usr/bin/python3 /usr/bin/python -RUN pip3 install torch==1.12.0+cu116 -f https://download.pytorch.org/whl/torch_stable.html +RUN pip3 install --no-cache-dir torch==1.12.0+cu116 -f https://download.pytorch.org/whl/torch_stable.html COPY . . RUN if [ "$with_models" = "true" ]; then \ # install only the dependencies first - pip3 install -e .; \ + pip3 install --no-cache-dir -e .; \ # initialize the language models if [ ! -z "$models" ]; then \ ./scripts/install_models.py --load_only_lang_codes "$models"; \