World map

 

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

The recipe has ARG SHOP=kancil and ENV GREETING. Built with --build-arg SHOP=pasar, the image prints Menu for pasar. Docker transcript: $ cat Dockerfile FROM alpine:3.22 ARG SHOP=kancil ENV GREETING="Selamat datang" RUN echo "Menu for $SHOP" > /menu.txt CMD ["cat", "/menu.txt"] $ docker build --build-arg SHOP=pasar -t menu:pasar . [+] Building 1.3s (6/6) FINISHED docker:default => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 163B 0.0s => [internal] load metadata for docker.io/library/alpine:3.22 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [1/2] FROM docker.io/library/alpine:3.22@sha256:2e0b81d60597f449baa56d 0.0s => => resolve docker.io/library/alpine:3.22@sha256:2e0b81d60597f449baa56d 0.0s => [2/2] RUN echo "Menu for pasar" > /menu.txt 1.2s => exporting to image 0.1s => => exporting layers 0.0s => => exporting manifest sha256:d3c646d00adf6045d91db20c22d64553848796ddc 0.0s => => exporting config sha256:a5d589f88cc15649078ffb6d652ef2816f0fffbfc84 0.0s => => exporting attestation manifest sha256:aa16cfcc92916117dc9d043936d37 0.0s => => exporting manifest list sha256:780c291d914f96a80974fd5abc4735c49b67 0.0s => => naming to docker.io/library/menu:pasar 0.0s => => unpacking to docker.io/library/menu:pasar 0.0s $ docker run --rm menu:pasar Menu for pasar

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.

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

      1. docker build --build-arg SHOP=pasar -t menu:pasar .
      2. docker run --rm menu:pasar printenv SHOP

      0 of 3 steps done · Your ticks are saved.