From 38b190139f2ccf5fa65fb105753b064578c71dde Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 3 Jun 2026 19:55:51 +0000 Subject: [PATCH 1/5] Add multi-stage builds section to Docker training MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 7 slides covering the problem (bloated single-stage images), the two-stage Dockerfile pattern, the 838 MB → 12 MB size result, named stages and COPY --from, the --target flag for dev vs prod targets, and a lab slide with the 4 hands-on tasks. Section is inserted after docker-images in index.html. https://claude.ai/code/session_01Kpsk26gHyUxXYL46tVMdjm --- docker-training/CLAUDE.md | 19 +- docker-training/index.html | 1 + .../sections/multistage-builds.html | 168 ++++++++++++++++++ 3 files changed, 179 insertions(+), 9 deletions(-) create mode 100644 docker-training/sections/multistage-builds.html diff --git a/docker-training/CLAUDE.md b/docker-training/CLAUDE.md index 1f870ba..bc1bd32 100644 --- a/docker-training/CLAUDE.md +++ b/docker-training/CLAUDE.md @@ -19,15 +19,16 @@ Sections are loaded in this order (see `index.html`): 9. `docker-desktop.html` — Docker Desktop 10. `docker-commands.html` — CLI commands 11. `docker-images.html` — images & Dockerfiles -12. `docker-networking.html` — container networking -13. `docker-volumes.html` — persistent storage -14. `docker-compose.html` — Docker Compose -15. `devops-docker.html` — DevOps with Docker -16. `docker-swarm.html` — Swarm orchestration -17. `serverless.html` — serverless concepts -18. `docker-kubernetes.html` — Kubernetes overview -19. `monitoring.html` — container monitoring -20. `resources.html` — further resources +12. `multistage-builds.html` — multi-stage builds +13. `docker-networking.html` — container networking +14. `docker-volumes.html` — persistent storage +15. `docker-compose.html` — Docker Compose +16. `devops-docker.html` — DevOps with Docker +17. `docker-swarm.html` — Swarm orchestration +18. `serverless.html` — serverless concepts +19. `docker-kubernetes.html` — Kubernetes overview +20. `monitoring.html` — container monitoring +21. `resources.html` — further resources ## Local Development diff --git a/docker-training/index.html b/docker-training/index.html index 3291026..d7f69fe 100644 --- a/docker-training/index.html +++ b/docker-training/index.html @@ -40,6 +40,7 @@
+
diff --git a/docker-training/sections/multistage-builds.html b/docker-training/sections/multistage-builds.html new file mode 100644 index 0000000..6000497 --- /dev/null +++ b/docker-training/sections/multistage-builds.html @@ -0,0 +1,168 @@ +

Multi-Stage Builds

+ +
+

The Problem — Bloated Images

+
+
+

+FROM golang:1.23
+
+WORKDIR /app
+COPY main.go .
+RUN go build -o hello main.go
+
+EXPOSE 8080
+CMD ["./hello"]
+      
+

+$ docker image ls hello-single
+REPOSITORY     SIZE
+hello-single   838MB
+      
+
+
+
+ +

The Go compiler, toolchain, and build tools end up in the final image — but are never needed at runtime.

+
+
+ +

More packages mean more vulnerabilities, slower pulls, and higher storage costs.

+
+
+
+
+ +
+

Multi-Stage Builds

+
+
+

+# Stage 1: Build
+FROM golang:1.23 AS builder
+WORKDIR /app
+COPY main.go .
+RUN CGO_ENABLED=0 go build -o hello main.go
+
+# Stage 2: Minimal runtime
+FROM alpine:3.21
+WORKDIR /app
+COPY --from=builder /app/hello .
+EXPOSE 8080
+CMD ["./hello"]
+      
+
+
+
+ +

Stage 1 compiles the app using the full golang:1.23 image.

+
+
+ +

Stage 2 starts fresh from alpine:3.21 — only the compiled binary is copied over.

+
+
+ +

Build tools are discarded and never reach the final image.

+
+
+
+
+ +
+

The Result — 98% Smaller

+
+
+ +

Single-Stage

+

Go toolchain + compiler + sources + app

+

+hello-single   838 MB
+      
+
+
+ +

Multi-Stage

+

Alpine Linux + compiled binary only

+

+hello-multi    12.1 MB
+      
+
+
+
+ +
+

Named Stages & COPY --from

+
+
+

Assign names with AS

+

+FROM golang:1.23 AS builder
+FROM alpine:3.21 AS runtime
+      
+

Reference by name or number

+

+# By name (preferred)
+COPY --from=builder /app/hello .
+
+# From an external image
+COPY --from=nginx:latest \
+  /etc/nginx/nginx.conf /nginx.conf
+      
+
+
+ +

Copy files from any previous build stage — or directly from an external image — without adding the full image to your final result.

+
+
+
+ +
+

One Dockerfile, Multiple Targets

+
+
+

+# Production: run all stages
+$ docker image build \
+  --tag hello-multi:1.0 .
+
+# Dev: stop at the builder stage
+$ docker image build \
+  --target builder \
+  --tag hello-dev:1.0 .
+      
+

+REPOSITORY   SIZE
+hello-multi  12.1 MB   # production
+hello-dev    838 MB    # full toolchain
+      
+
+
+
+ +

Production

+

Minimal image — only what is needed to run.

+
+
+ +

Development

+

Full toolchain for debugging — from the same Dockerfile.

+
+
+
+
+ +
+

Lab — Multi-Stage Builds

+ +

+ + github.com/elft3r/training — Docker/kickstart/chapters/multistage-builds.md + +

+
From 7317acf02b297981c6eed97d9fe079d3c0013ca8 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 3 Jun 2026 20:04:59 +0000 Subject: [PATCH 2/5] Fix card sizing and consistency in multistage-builds section MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add text-base to right-column card containers so cards scale down from the slide's text-4xl base size - Tighten gap-4 → gap-2 on right columns to reduce vertical overflow - Add fragment class to Problem slide cards for consistent behaviour - Remove h3 from One Dockerfile/Multiple Targets cards to match the icon + paragraph pattern used on other slides - Remove lab slide https://claude.ai/code/session_01Kpsk26gHyUxXYL46tVMdjm --- .../sections/multistage-builds.html | 33 +++++-------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/docker-training/sections/multistage-builds.html b/docker-training/sections/multistage-builds.html index 6000497..cfe840e 100644 --- a/docker-training/sections/multistage-builds.html +++ b/docker-training/sections/multistage-builds.html @@ -20,12 +20,12 @@

The Problem — Bloated Images

hello-single 838MB -
-
+
+

The Go compiler, toolchain, and build tools end up in the final image — but are never needed at runtime.

-
+

More packages mean more vulnerabilities, slower pulls, and higher storage costs.

@@ -52,7 +52,7 @@

Multi-Stage Builds

CMD ["./hello"]
-
+

Stage 1 compiles the app using the full golang:1.23 image.

@@ -110,7 +110,7 @@

Reference by name or number

/etc/nginx/nginx.conf /nginx.conf
-
+

Copy files from any previous build stage — or directly from an external image — without adding the full image to your final result.

@@ -137,32 +137,15 @@

One Dockerfile, Multiple Targets

hello-dev 838 MB # full toolchain
-
+
-

Production

-

Minimal image — only what is needed to run.

+

Production — minimal image, only what is needed to run.

-

Development

-

Full toolchain for debugging — from the same Dockerfile.

+

Development — full toolchain for debugging, from the same Dockerfile.

- -
-

Lab — Multi-Stage Builds

-
    -
  • Task 1 Build a single-stage Go image and inspect its size (~838 MB)
  • -
  • Task 2 Refactor to a multi-stage Dockerfile and compare sizes (12 MB)
  • -
  • Task 3 Use named stages and COPY --from to add a health-check binary
  • -
  • Task 4 Use --target to build a dev image with the full toolchain
  • -
-

- - github.com/elft3r/training — Docker/kickstart/chapters/multistage-builds.md - -

-
From 5d690d48cfb2461d350461395de2b0443ed45139 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 3 Jun 2026 20:08:37 +0000 Subject: [PATCH 3/5] Shorten card text instead of reducing font size Replace verbose card descriptions with concise copy so cards fit at the default slide font size without any text-base overrides. https://claude.ai/code/session_01Kpsk26gHyUxXYL46tVMdjm --- .../sections/multistage-builds.html | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/docker-training/sections/multistage-builds.html b/docker-training/sections/multistage-builds.html index cfe840e..9dce860 100644 --- a/docker-training/sections/multistage-builds.html +++ b/docker-training/sections/multistage-builds.html @@ -20,14 +20,14 @@

The Problem — Bloated Images

hello-single 838MB
-
+
-

The Go compiler, toolchain, and build tools end up in the final image — but are never needed at runtime.

+

Compiler & build tools ship in the final image — never needed at runtime.

-

More packages mean more vulnerabilities, slower pulls, and higher storage costs.

+

More packages = more vulnerabilities, slower pulls, higher costs.

@@ -52,18 +52,18 @@

Multi-Stage Builds

CMD ["./hello"]
-
+
-

Stage 1 compiles the app using the full golang:1.23 image.

+

Stage 1 compiles using the full golang:1.23 image.

-

Stage 2 starts fresh from alpine:3.21 — only the compiled binary is copied over.

+

Stage 2 copies only the binary into a fresh alpine:3.21 image.

-

Build tools are discarded and never reach the final image.

+

Build tools never reach the final image.

@@ -110,9 +110,9 @@

Reference by name or number

/etc/nginx/nginx.conf /nginx.conf
-
+
-

Copy files from any previous build stage — or directly from an external image — without adding the full image to your final result.

+

Copy from any build stage or external image — without including it in the final result.

@@ -137,14 +137,14 @@

One Dockerfile, Multiple Targets

hello-dev 838 MB # full toolchain
-
+
-

Production — minimal image, only what is needed to run.

+

Production — minimal image, binary only.

-

Development — full toolchain for debugging, from the same Dockerfile.

+

Development — full toolchain, same Dockerfile.

From 756fbbf78ee9a307c9dd6db9d33e7e22a808a0bd Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 3 Jun 2026 20:16:14 +0000 Subject: [PATCH 4/5] Replace oversized cards with styled-list on Multi-Stage Builds slide https://claude.ai/code/session_01Kpsk26gHyUxXYL46tVMdjm --- .../sections/multistage-builds.html | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/docker-training/sections/multistage-builds.html b/docker-training/sections/multistage-builds.html index 9dce860..10b4a5c 100644 --- a/docker-training/sections/multistage-builds.html +++ b/docker-training/sections/multistage-builds.html @@ -52,20 +52,11 @@

Multi-Stage Builds

CMD ["./hello"]
-
-
- -

Stage 1 compiles using the full golang:1.23 image.

-
-
- -

Stage 2 copies only the binary into a fresh alpine:3.21 image.

-
-
- -

Build tools never reach the final image.

-
-
+ From 49e0d9860ec439a203ede244ee61dee428363fae Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 3 Jun 2026 20:20:16 +0000 Subject: [PATCH 5/5] Fix accessibility and size unit consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add aria-hidden="true" to all decorative FA icons, consistent with other sections in the presentation - Normalise 838MB → 838 MB to match the format used elsewhere https://claude.ai/code/session_01Kpsk26gHyUxXYL46tVMdjm --- docker-training/sections/multistage-builds.html | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docker-training/sections/multistage-builds.html b/docker-training/sections/multistage-builds.html index 10b4a5c..ef5e9e8 100644 --- a/docker-training/sections/multistage-builds.html +++ b/docker-training/sections/multistage-builds.html @@ -17,16 +17,16 @@

The Problem — Bloated Images


 $ docker image ls hello-single
 REPOSITORY     SIZE
-hello-single   838MB
+hello-single   838 MB
       
- +

Compiler & build tools ship in the final image — never needed at runtime.

- +

More packages = more vulnerabilities, slower pulls, higher costs.

@@ -64,7 +64,7 @@

Multi-Stage Builds

The Result — 98% Smaller

- +

Single-Stage

Go toolchain + compiler + sources + app


@@ -72,7 +72,7 @@ 

Single-Stage

- +

Multi-Stage

Alpine Linux + compiled binary only


@@ -102,7 +102,7 @@ 

Reference by name or number

- +

Copy from any build stage or external image — without including it in the final result.

@@ -130,11 +130,11 @@

One Dockerfile, Multiple Targets

- +

Production — minimal image, binary only.

- +

Development — full toolchain, same Dockerfile.