BM: Baca dalam Bahasa Melayu
World D2: Recipes
Your first recipe: FROM, COPY, CMD
You will learn: to write a three-line Dockerfile and bake it into an image.
Checked with Docker Engine 29 on 31 Oct 2026
The problem
Your hello app works on your laptop. On Aina’s laptop it crashes. She has an older Node. What fixes this for good?
Pick one answer.
Watch
Your laptop~/hello
- No open hatches
Lunchboxes (containers)
- No containers yet
Frozen packs (images)
- node:24-alpine4 layers · 244MB
0 containers (0 running), 1 images, 0 lockers.
A Dockerfile: The recipe: step-by-step lines that make an image. is a recipe for an image. FROM picks a frozen base pack. COPY adds your food. CMD says what to do when the box opens.
Try it
Put the recipe in order. The top line runs first.
First line at the top. Put these in order. Use the arrows, or drag.
- COPY hello.js /hello.js
- FROM node:24-alpine
- CMD ["node", "/hello.js"]
Hint
You need a base pack before you can add food to it.Watch
Your laptop~/hello
- No open hatches
Lunchboxes (containers)
- No containers yet
Frozen packs (images)
- node:24-alpine4 layers · 244MB
0 containers (0 running), 1 images, 0 lockers.
docker build -t hello:1.0 . bakes the recipe into an image. -t gives it a name and a tag. The dot means “use this folder”.
Try it
Your turn. Build the image, then run it once.
Your laptop~/hello
- No open hatches
Lunchboxes (containers)
- No containers yet
Frozen packs (images)
- node:24-alpine4 layers · 244MB
0 containers (0 running), 1 images, 0 lockers.
Hint
Typedocker build -t hello:1.0 . first. Then docker run --rm hello:1.0.Predict
You change the message in hello.js. Then you run hello:1.0 again. What prints?
Pick one answer.
Check
Your laptop~/hello
- No open hatches
Lunchboxes (containers)
- No containers yet
Frozen packs (images)
- node:24-alpine4 layers · 244MB
0 containers (0 running), 1 images, 0 lockers.
The old pack still says hello. A new build packs the new file. Change the recipe or the food? Build again.
You did it!
You can now write a recipe and bake it into an image.
Go deeper (optional)
A website on the nginx base needs no CMD. The base pack already has one. docker build reads the file called Dockerfile in the folder you name.
Real rep (optional), on your own computer:
Real mission
mkdir hello && cd hellodocker build -t hello:1.0 .docker run --rm hello:1.0
0 of 4 steps done · Your ticks are saved.
Bahasa Melayu
Aplikasi hello anda jalan di laptop anda. Di laptop Aina, ia gagal. Node dia versi lama. Apa yang boleh baiki untuk selamanya?
Dockerfile ialah resepi untuk image. FROM pilih pek beku asas. COPY masukkan makanan anda. CMD beritahu apa nak buat bila bekas dibuka.
Susun resepi ini. Baris paling atas jalan dulu.
docker build -t hello:1.0 . bakar resepi menjadi image. -t beri nama dan tag. Titik itu maksudnya “guna folder ini”.
Giliran anda. Bina image itu, kemudian jalankan sekali.
docker build -t hello:1.0 . dulu. Kemudian docker run --rm hello:1.0.Anda tukar mesej dalam hello.js. Kemudian anda jalankan hello:1.0 lagi. Apa yang keluar?
Pek lama masih kata hello. Binaan baharu bungkus fail baharu. Tukar resepi atau makanan? Bina semula.
Kini anda boleh tulis resepi tiga baris dan bakar menjadi image.
You finished this before. Practice is always welcome!
Official docs: Docker docs: Writing a Dockerfile · Dockerfile reference · docker build
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?