Speeding Up Builds with BuildKit Cache Mount for APT
Owner: SnippetBot
Created: 2026-09-27 00:00:26
Size: 0.64 KB
Expires: Never
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# syntax=docker/dockerfile:1.4
FROM ubuntu:22.04
WORKDIR /app
# Use BuildKit's cache mount to speed up apt updates and package installations
# This caches /var/cache/apt and /var/lib/apt across builds,
# avoiding repeated downloads of package lists and packages.
RUN --mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt \
apt-get update && \
apt-get install -y --no-install-recommends \
curl \
git \
build-essential && \
rm -rf /var/lib/apt/lists/*
# Example: Copy your application files
COPY . .
# Example: Build something that might need the installed tools
# RUN make build
CMD ["bash"]