BM: Baca dalam Bahasa Melayu
World D2: Recipes
ARG vs ENV
You will learn: settings for baking time (ARG) and settings that stay in the pack (ENV).
Checked with Docker Engine 29 on 31 Oct 2026
The problem
You bake the same menu for two shops: Kancil and Pasar. Only the shop name changes. Do you need two recipes?
Pick one answer.
Watch
Your laptop~/menu
- No open hatches
Lunchboxes (containers)
- No containers yet
Frozen packs (images)
- alpine:3.221 layers · 12.9MB
0 containers (0 running), 1 images, 0 lockers.
build argument (ARG): A setting used only while baking. It is not kept in the running container. is a blank for baking time. --build-arg SHOP=pasar fills it in. Without it, the default kancil is used.
Try it
Build the command that bakes a menu for Pasar.
Tap the pieces in the right order.
Predict
The container from menu:pasar runs printenv SHOP. What prints?
Pick one answer.
Try it
ENV GREETING does stay in the pack. Print it. Then change it with -e and print it again.
Your laptop~/menu
- No open hatches
Lunchboxes (containers)
- No containers yet
Frozen packs (images)
- alpine:3.221 layers · 12.9MB
- menu:1.02 layers · 12.8MB
0 containers (0 running), 2 images, 0 lockers.
Hint
-e goes before the image name.Check
ARG or ENV?
Drag a card into a box. Or tap the card, then tap the box.
You did it!
You can now pick ARG for baking and ENV for running.
Go deeper (optional)
Never pass a password with ARG or ENV. docker history shows ARG values, and ENV stays in every container. Lesson 12 shows the safe way: build secrets.
An ARG before FROM can pick the base itself: ARG BASE=nginx:latest, then FROM ${BASE}. Lesson 9 uses this trick.
Real mission
docker build --build-arg SHOP=pasar -t menu:pasar .docker run --rm menu:pasar printenv SHOP
0 of 3 steps done · Your ticks are saved.
Bahasa Melayu
Anda bakar menu yang sama untuk dua kedai: Kancil dan Pasar. Hanya nama kedai berbeza. Perlukah dua resepi?
ARG ialah ruang kosong untuk masa membakar. --build-arg SHOP=pasar mengisinya. Tanpanya, nilai asal kancil dipakai.
Bina arahan yang bakar menu untuk Pasar.
Container dari menu:pasar jalankan printenv SHOP. Apa yang keluar?
ENV GREETING memang kekal dalam pek. Cetak ia. Kemudian tukar dengan -e dan cetak lagi.
-e diletak sebelum nama image.ARG atau ENV?
Kini anda boleh pilih ARG untuk membakar dan ENV untuk berjalan.
You finished this before. Practice is always welcome!
Official docs: Docker docs: Build variables · Dockerfile reference: ARG · Dockerfile reference: ENV
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?