Skip to content

Commit da42377

Browse files
bartlomiejuclaude
andcommitted
fix: Docker multi-stage build missing DENO_DIR copy
The multi-stage build example didn't copy DENO_DIR from the builder stage, causing dependencies to be re-downloaded at runtime. Also improved layer caching by copying config files before source code in both examples. Closes #2935 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2fed5bc commit da42377

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

runtime/reference/docker.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ To use the official image, create a `Dockerfile` in your project directory:
1414
```dockerfile
1515
FROM denoland/deno:latest
1616

17-
# Create working directory
1817
WORKDIR /app
1918

20-
# Copy source
21-
COPY . .
19+
# Cache dependencies by copying config files first
20+
COPY deno.json deno.lock ./
21+
RUN deno install
2222

23-
# Install dependencies (use just `deno install` if deno.json has imports)
23+
# Copy source and install entrypoint
24+
COPY . .
2425
RUN deno install --entrypoint main.ts
2526

2627
# Run the app
@@ -37,17 +38,27 @@ For smaller production images:
3738
# Build stage
3839
FROM denoland/deno:latest AS builder
3940
WORKDIR /app
41+
42+
# Cache dependencies by copying config files first
43+
COPY deno.json deno.lock ./
44+
RUN deno install
45+
46+
# Then copy source and install entrypoint
4047
COPY . .
41-
# Install dependencies (use just `deno install` if deno.json has imports)
4248
RUN deno install --entrypoint main.ts
4349

4450
# Production stage
4551
FROM denoland/deno:latest
4652
WORKDIR /app
4753
COPY --from=builder /app .
54+
COPY --from=builder /deno-dir /deno-dir
4855
CMD ["deno", "run", "--allow-net", "main.ts"]
4956
```
5057

58+
The `DENO_DIR` (which defaults to `/deno-dir/` in the official Docker image)
59+
contains cached dependencies from `deno install`. Copying it to the production
60+
stage ensures dependencies don't need to be re-downloaded at runtime.
61+
5162
#### Permission Flags
5263

5364
Specify required permissions explicitly:

0 commit comments

Comments
 (0)