From 99c41c7e34402dc437a349be42704281d980f50c Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Thu, 1 Aug 2024 23:45:13 +0800 Subject: [PATCH] Optimize Dockerfile to reduce image size and improve build efficiency - Merge apt-related RUN commands in builder and final stages - Remove redundant apt-get clean (automatically handled by base image) - Consolidate cleanup operations within the same layer for effective size reduction Reference: - https://docs.docker.com/build/building/best-practices/#apt-get --- application/Dockerfile | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/application/Dockerfile b/application/Dockerfile index dde88503..d076bc41 100644 --- a/application/Dockerfile +++ b/application/Dockerfile @@ -4,14 +4,11 @@ FROM ubuntu:24.04 as builder ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && \ - apt-get install -y software-properties-common - -RUN add-apt-repository ppa:deadsnakes/ppa - + apt-get install -y software-properties-common && \ + add-apt-repository ppa:deadsnakes/ppa && \ # Install necessary packages and Python -RUN apt-get update && \ + apt-get update && \ apt-get install -y --no-install-recommends gcc wget unzip libc6-dev python3.11 python3.11-distutils python3.11-venv && \ - apt-get clean && \ rm -rf /var/lib/apt/lists/* # Verify Python installation and setup symlink @@ -50,12 +47,10 @@ RUN pip install --no-cache-dir --upgrade pip && \ FROM ubuntu:24.04 as final RUN apt-get update && \ - apt-get install -y software-properties-common - -RUN add-apt-repository ppa:deadsnakes/ppa - + apt-get install -y software-properties-common && \ + add-apt-repository ppa:deadsnakes/ppa && \ # Install Python -RUN apt-get update && apt-get install -y --no-install-recommends python3.11 && \ + apt-get update && apt-get install -y --no-install-recommends python3.11 && \ ln -s /usr/bin/python3.11 /usr/bin/python && \ rm -rf /var/lib/apt/lists/*