Skip to content

Commit b645a9c

Browse files
committed
Use BuildKit cache mounts for apt-get to speed up Docker builds
1 parent ea09140 commit b645a9c

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

Dockerfile.base

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ COPY scripts/retry.sh /usr/local/bin/retry
1313
RUN chmod +x /usr/local/bin/retry
1414

1515
# ============ COMMON TOOLS ============
16-
RUN apt-get update && apt-get install -y \
16+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
17+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
18+
apt-get update && apt-get install -y --no-install-recommends \
1719
ca-certificates curl gnupg wget git vim \
1820
build-essential python3 \
1921
zip unzip jq netcat telnet \
2022
iputils-ping net-tools dnsutils \
21-
lsb-release openssl \
22-
&& rm -rf /var/lib/apt/lists/*
23+
lsb-release openssl
2324

2425
# ============ NODE.JS 22 ============
25-
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
26-
&& apt-get install -y nodejs \
26+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
27+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
28+
curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
29+
&& apt-get install -y --no-install-recommends nodejs \
2730
&& npm config set fetch-retries 5 \
2831
&& npm config set fetch-retry-mintimeout 20000 \
2932
&& npm config set fetch-retry-maxtimeout 120000
@@ -37,7 +40,9 @@ ENV PATH="/usr/local/go/bin:/root/go/bin:${PATH}" \
3740
# ============ PHP 8.1 + WEB SERVER ============
3841
# nginx: serves PHP API via php-fpm
3942
# postfix: mail relay for sending emails (configured to use mailhog)
40-
RUN apt-get update && apt-get install -y \
43+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
44+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
45+
apt-get update && apt-get install -y --no-install-recommends \
4146
php8.1-fpm php8.1-cli php8.1-mysql php8.1-pgsql php8.1-redis \
4247
php8.1-curl php8.1-zip php8.1-gd php8.1-mbstring php8.1-xml \
4348
php8.1-intl php8.1-xdebug php-mailparse php8.1-simplexml \
@@ -47,16 +52,16 @@ RUN apt-get update && apt-get install -y \
4752
php-pear php-dev libgeoip-dev php-mbstring \
4853
nginx postfix cron rsyslog openssh-server \
4954
default-mysql-client postgresql-client \
50-
tesseract-ocr geoip-bin geoipupdate \
51-
&& rm -rf /var/lib/apt/lists/*
55+
tesseract-ocr geoip-bin geoipupdate
5256

5357
# ============ DOCKER CLI ============
54-
RUN install -m 0755 -d /etc/apt/keyrings \
58+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
59+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
60+
install -m 0755 -d /etc/apt/keyrings \
5561
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg \
5662
&& chmod a+r /etc/apt/keyrings/docker.gpg \
5763
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \
58-
&& apt-get update && apt-get install -y docker-ce-cli docker-compose-plugin \
59-
&& rm -rf /var/lib/apt/lists/*
64+
&& apt-get update && apt-get install -y --no-install-recommends docker-ce-cli docker-compose-plugin
6065

6166
# ============ GOOGLE CLOUD SDK ============
6267
RUN curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-linux-x86_64.tar.gz \
@@ -70,7 +75,9 @@ ENV PATH="/opt/google-cloud-sdk/bin:${PATH}"
7075
RUN go install github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0
7176

7277
# Remove packages that conflict with our setup
73-
RUN apt-get update && apt-get remove -y apache2* sendmail* mlocate php-ssh2 || true && rm -rf /var/lib/apt/lists/*
78+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
79+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
80+
apt-get update && apt-get remove -y apache2* sendmail* mlocate php-ssh2 || true
7481

7582
# ============ GEOIP DATABASE ============
7683
# Copy fallback GeoIP database first, then try to download fresh version

0 commit comments

Comments
 (0)