docs(docker): split dependency install for better layer caching#3030
Merged
Conversation
lunadogbot
approved these changes
May 14, 2026
Contributor
lunadogbot
left a comment
There was a problem hiding this comment.
Splitting COPY deno.json deno.lock ./ + RUN deno install before COPY . . is the right caching shape — the dep layer only invalidates when deno.json/deno.lock change. COPY --from=builder /deno-dir /deno-dir in the multi-stage example matches DENO_DIR=/deno-dir/ baked into the denoland/deno image, so the runtime cache is preserved.
- nit:
last_modified: 2025-12-16in the frontmatter wasn't bumped — repo convention is to bump it for substantive content changes. - nit: basic example runs
deno installthendeno install --entrypoint main.ts— the second resolves everything frommain.tsanyway, so the first is purely a caching trick. Worth a one-line comment so readers don't think both are required. - nit:
COPY deno.json deno.lock ./fails the build if a project has nodeno.lockyet.COPY deno.json deno.lock* ./keeps it working for first-time users.
3 tasks
da42377 to
a62ead0
Compare
Rebases on 2.8 and switches the Dockerfile examples from `deno install --entrypoint main.ts` to `deno ci --prod --skip-types`. `deno ci` is the 2.8 install command intended for CI and image builds: it requires a committed lockfile, wipes any stale node_modules, and runs install with `--frozen` semantics. `--prod` drops devDependencies and `--skip-types` drops `@types/*` packages, both shrinking the resulting image without changing runtime behavior. Manifests (`deno.json`, `deno.lock`, `package.json*`) are copied before the full source tree so the install layer caches across source-only edits, in both the basic and multi-stage examples. Ref #2935
a62ead0 to
f9bf111
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebased onto the 2.8 branch and updated the Dockerfile examples to use
deno ciinstead ofdeno install --entrypoint main.ts.deno ciis the new 2.8 install command intended for CI and image builds — it requires a committed lockfile, wipes any stalenode_modules, and installs with--frozensemantics, so two builds of the same commit produce the same dependency tree.For production images, the examples pass
--prod --skip-types:--prodskipsdevDependenciesfrompackage.jsonand--skip-typesdrops@types/*packages from bothdeno.jsonimports andpackage.jsondependencies. Both shrink the resulting image without changing runtime behavior.The original layer-caching change is preserved: manifests (
deno.json,deno.lock,package.json*) are copied before the full source tree so editing source code doesn't invalidate the dependency install layer, in both the basic and multi-stage examples. TheDENO_DIRcopy in the multi-stage example is untouched — that part of #2935 already landed in #3122.Ref #2935