dev.Dockerfile: use cache mounts to speed up rebuilding
What changed, and why it matters
This change only modifies the developer Dockerfile to use Docker BuildKit cache mounts for Go build caches, making image rebuilds faster. It is a build-performance improvement with no security relevance.
No security action needed. Reviewers may verify that BuildKit cache mounts do not leak unintended state between builds, which is standard behavior and not a vulnerability in this context.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit updates dev.Dockerfile to add --mount=type=cache,target=/go/pkg/mod and --mount=type=cache,target=/root/.cache/go-build to the RUN instruction that builds lnd. It also documents the new BuildKit requirement in the 0.22.0 release notes. This is purely a Docker build optimization; no application code, dependencies, permissions, secrets, or network behavior are changed.
Changed components
dev.Dockerfiledocs/release-notes/release-notes-0.22.0.mdInspect captured patch +18 / −1
diff --git a/dev.Dockerfile b/dev.Dockerfile
index 8270962..d8eaa68 100644
--- a/dev.Dockerfile
+++ b/dev.Dockerfile
@@ -18,7 +18,13 @@ RUN apk add --no-cache --update alpine-sdk \
COPY . /go/src/github.com/lightningnetwork/lnd
# Install/build lnd.
-RUN cd /go/src/github.com/lightningnetwork/lnd \
+# Note: When using `docker build`, setting the environmental variable
+# `DOCKER_BUILDKIT=1` is required to enable
+# [BuildKit](https://docs.docker.com/build/buildkit)
+# so that the cache mounts can be used.
+RUN --mount=type=cache,target=/go/pkg/mod \
+ --mount=type=cache,target=/root/.cache/go-build \
+ cd /go/src/github.com/lightningnetwork/lnd \
&& make \
&& make install-all tags="signrpc walletrpc chainrpc invoicesrpc peersrpc kvdb_sqlite"
diff --git a/docs/release-notes/release-notes-0.22.0.md b/docs/release-notes/release-notes-0.22.0.md
index 75454ee..2f7f0ca 100644
--- a/docs/release-notes/release-notes-0.22.0.md
+++ b/docs/release-notes/release-notes-0.22.0.md
@@ -100,6 +100,17 @@
## Tooling and Documentation
+* [`dev.Dockerfile` now uses](https://github.com/lightningnetwork/lnd/pull/10903)
+ [cache mounts](https://docs.docker.com/build/cache/optimize/#use-cache-mounts)
+ to cache the `GOMODCACHE` and `GOCACHE` directories so that dependencies don't
+ need to be re-downloaded and re-built every time the image is re-created.
+ As a result of this change, `dev.Dockerfile` now requires
+ [BuildKit](https://docs.docker.com/build/buildkit) to build. When using
+ `docker build`, this can be enabled by setting the environmental variable
+ `DOCKER_BUILDKIT=1`. BuildKit also does not unnecessarily rebuild images when
+ the build context is a remote git repository because COPY layers are more
+ smartly compared to cache.
+
# Contributors (Alphabetical Order)
* bitromortac
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.