BM: Baca dalam Bahasa Melayu
World D2: Recipes
WORKDIR, RUN, ENV and EXPOSE
You will learn: four more recipe lines, and why EXPOSE does not open the hatch.
Checked with Docker Engine 29 on 31 Oct 2026
The problem
A recipe says COPY server.js . and nothing else. The node base sets no work folder. Where does server.js land?
Pick one answer.
Watch
Your laptop~/api
- No open hatches
Lunchboxes (containers)
- No containers yet
Frozen packs (images)
- node:24-alpine4 layers · 244MB
0 containers (0 running), 1 images, 0 lockers.
WORKDIR /app is your work counter. Every later line works there. RUN cooks while baking: here it installs packages. pwd prints the counter: /app.
Try it
Some lines bake a layer. Others only stick a note on the pack. Sort them.
Drag a card into a box. Or tap the card, then tap the box.
Try it
The image is built. Run it with hatch 3000 open, then knock with curl.
Your laptop~/api
- No open hatches
Lunchboxes (containers)
- No containers yet
Frozen packs (images)
- api:1.08 layers · 244MB
- node:24-alpine4 layers · 244MB
0 containers (0 running), 2 images, 0 lockers.
Hint
-p 3000:3000 opens the hatch: laptop port, then container port.Predict
The recipe says EXPOSE 3000. You run the image with no -p. Can your laptop reach port 3000?
Pick one answer.
Check
Your laptop~/api
- No open hatches
Lunchboxes (containers)
- No containers yet
Frozen packs (images)
- node:24-alpine4 layers · 244MB
0 containers (0 running), 1 images, 0 lockers.
Real error: Couldn't connect to server. Plain words: no hatch is open. docker ps shows 3000/tcp with no arrow.
Try it
ENV PORT=3000 is only a default. Build the command that runs the API on port 4000.
Tap the pieces in the right order.
You did it!
You can now use WORKDIR, RUN, ENV and EXPOSE.
Go deeper (optional)
Chain related commands in one RUN with &&. One RUN is one layer. EXPOSE also helps docker run -P, which opens every exposed port on a random laptop port.
Real mission
docker build -t hello:1.1 .docker run --rm hello:1.1 pwd
0 of 3 steps done · Your ticks are saved.
Bahasa Melayu
Satu resepi tulis COPY server.js . sahaja. Asas node tak tetapkan folder kerja. Di mana server.js mendarat?
WORKDIR /app ialah kaunter kerja anda. Semua baris selepasnya bekerja di situ. RUN memasak semasa membakar: di sini ia pasang pakej. pwd cetak kaunter itu: /app.
Sesetengah baris bakar satu layer (lapisan). Yang lain cuma tampal nota pada pek. Asingkan mereka.
Image sudah dibina. Jalankan dengan tingkap 3000 terbuka, kemudian ketuk dengan curl.
-p 3000:3000 buka tingkap: port laptop, kemudian port container.Resepi tulis EXPOSE 3000. Anda jalankan image tanpa -p. Boleh laptop anda capai port 3000?
Ralat sebenar: Couldn't connect to server. Maksudnya: tiada tingkap terbuka. docker ps tunjuk 3000/tcp tanpa anak panah.
ENV PORT=3000 cuma nilai asal. Bina arahan yang jalankan API di port 4000.
Kini anda boleh guna WORKDIR, RUN, ENV dan EXPOSE.
You finished this before. Practice is always welcome!
Official docs: Dockerfile reference: WORKDIR · Dockerfile reference: RUN · Dockerfile reference: ENV · Dockerfile reference: EXPOSE
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?