Skip to content

Commit 00ef432

Browse files
fibibotlunadogbotbartlomieju
authored
Fix #2935: multi-stage Docker build doesn't ship deps to the runtime stage (#3122)
Co-authored-by: lunadogbot <lunadogbot@users.noreply.github.com> Co-authored-by: fibibot <fibibot@users.noreply.github.com> Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
1 parent 2d7974f commit 00ef432

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

runtime/reference/docker.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,28 @@ For smaller production images:
3636
```dockerfile
3737
# Build stage
3838
FROM denoland/deno:latest AS builder
39+
# Point Deno's cache at a known location so it can be copied to the next stage
40+
ENV DENO_DIR=/deno-dir
3941
WORKDIR /app
4042
COPY . .
4143
# Install dependencies (use just `deno install` if deno.json has imports)
4244
RUN deno install --entrypoint main.ts
4345

4446
# Production stage
4547
FROM denoland/deno:latest
48+
ENV DENO_DIR=/deno-dir
4649
WORKDIR /app
4750
COPY --from=builder /app .
51+
# Copy the populated Deno cache so the runtime stage has the dependencies
52+
COPY --from=builder /deno-dir /deno-dir
4853
CMD ["deno", "run", "--allow-net", "main.ts"]
4954
```
5055

56+
Without copying `$DENO_DIR`, `deno install` only writes to Deno's global cache
57+
inside the builder stage — those files do not travel with
58+
`COPY --from=builder /app .`, so the container re-downloads dependencies on
59+
first run.
60+
5161
#### Permission Flags
5262

5363
Specify required permissions explicitly:

0 commit comments

Comments
 (0)