World map

 

BM: Baca dalam Bahasa Melayu

World D2: Recipes · Boss challenge

Shrink ray

You will learn: to pack a real site with nginx: small, non-root and reachable.

Checked with Docker Engine 29 on 31 Oct 2026

The problem

The diary folder has index.html, style.css, notes.txt and a Dockerfile. The recipe picks its base with ARG BASE=nginx:latest. Docker transcript: $ ls Dockerfile index.html notes.txt style.css $ cat Dockerfile ARG BASE=nginx:latest FROM ${BASE} COPY . /usr/share/nginx/html/

Your laptop~/diary

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • nginx:1.30-alpine8 layers · 93.5MB
  • nginx:latest7 layers · 243MB

0 containers (0 running), 2 images, 0 lockers.

Boss: the Shrink ray! Pack your diary site with nginx. Finish line: under 100MB, no secret notes inside, and not running as root.

Try it

Stage 1: make it work. Build diary:1.0 and serve it on laptop port 8080.

Your laptop~/diary

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • nginx:1.30-alpine8 layers · 93.5MB
  • nginx:latest7 layers · 243MB

0 containers (0 running), 2 images, 0 lockers.

Check

docker images says diary:1.0 is 241MB. The target is under 100MB. Which move helps most?

Pick one answer.

Try it

Stage 2: plan the shrink. Get the meal pack to 70MB or less.

Shrink the meal pack under 70MB. Every button is a real trick.

Image size 186MB

Target: 70MBStart: 186MB

Base image

Recipe tricks

Dockerfile

FROM nginx:1.29
COPY . /usr/share/nginx/html

Try it

Stage 3: shrink for real. Leave notes.txt at home, and build diary:2.0 on nginx:1.30-alpine.

Your laptop~/diary

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • nginx:1.30-alpine8 layers · 93.5MB
  • nginx:latest7 layers · 243MB

0 containers (0 running), 2 images, 0 lockers.

Predict

You add only USER nginx to the recipe. What happens when the box starts?

Pick one answer.

Try it

Stage 4: no root. This recipe already gives nginx its folders. Add USER nginx, build diary:3.0, run it on 8080, and knock.

Your laptop~/diary

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • nginx:1.30-alpine8 layers · 93.5MB

0 containers (0 running), 1 images, 0 lockers.

You did it!

You can now pack a real site: small, safe and non-root.

Go deeper (optional)

Why the chown line? nginx writes its cache to /var/cache/nginx and its process id to /run/nginx.pid. As root, it may. As nginx, only if it owns them. Some platforms block low ports for normal users. Many teams use 8080.

Real mission

  1. docker images

0 of 4 steps done · Your ticks are saved.