Skip to content

Commit 9829b7b

Browse files
Optimize Dockerfile for improved cleanup and smaller image size
This commit optimizes the Dockerfile to enhance the cleanup process and reduce the resulting image size. The changes are as follows: 1. Consolidated the `wget`, `dpkg`, and removal of the downloaded .deb file and apt `/var/lib/apt/lists/*` into a single `RUN` command. This effectively reduces the image size as the cleanup occurs in the same Docker layer. This approach replaces the unnecessary `apt-get clean` that is automatically performed in Debian/Ubuntu base images. 2. Use `--no-install-recommends` flag with `apt-get install` to prevent unnecessary packages from being installed. 3. Apply `--no-cache-dir` flag when using `pip install` to prevent caching and reduce image size. These changes result in a more efficient Docker build process and a smaller, cleaner final Docker image. Specifically, the image size was reduced from 977MB to 949MB, as you can see below. ``` $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE smallweb after 7206ce8c6966 12 minutes ago 949MB smallweb before c92947befbe9 12 minutes ago 977MB ```
1 parent 295a586 commit 9829b7b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

Dockerfile

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,25 @@ ENV BUCKET kagi-us-central1-smallweb
77
ENV PORT 8080
88

99
RUN set -e; \
10-
apt-get update -y && apt-get install -y \
10+
apt-get update -y && apt-get install --no-install-recommends -y \
1111
libpq-dev \
1212
curl \
1313
gcc \
1414
tini \
1515
lsb-release \
1616
wget \
17-
fuse
18-
19-
RUN wget https://github.com/GoogleCloudPlatform/gcsfuse/releases/download/v1.2.0/gcsfuse_1.2.0_amd64.deb
20-
RUN dpkg -i gcsfuse_1.2.0_amd64.deb
21-
RUN apt-get clean
17+
fuse && \
18+
wget https://github.com/GoogleCloudPlatform/gcsfuse/releases/download/v1.2.0/gcsfuse_1.2.0_amd64.deb && \
19+
dpkg -i gcsfuse_1.2.0_amd64.deb && \
20+
rm -rf gcsfuse_1.2.0_amd64.deb /var/lib/apt/lists/*
2221

2322
WORKDIR /app
2423

2524
COPY gcsfuse_run.sh gcsfuse_run.sh
2625
RUN chmod +x gcsfuse_run.sh
2726

2827
COPY app/requirements.txt requirements.txt
29-
RUN pip3 install -r requirements.txt
28+
RUN pip3 install --no-cache-dir -r requirements.txt
3029

3130
COPY app/ .
3231
EXPOSE $PORT

0 commit comments

Comments
 (0)