World map

 

BM: Baca dalam Bahasa Melayu

World D2: Recipes

CMD vs ENTRYPOINT

You will learn: which part of a start command you can swap, and which part stays.

Checked with Docker Engine 29 on 31 Oct 2026

The problem

The image say:1.0 has CMD ["echo", "Selamat datang!"]. You type docker run --rm say:1.0 echo Hai. What prints?

Pick one answer.

Watch

say:1.0 prints Selamat datang! by itself. With echo Hai after the image name, it prints only Hai. Docker transcript: $ cat sayer/Dockerfile FROM alpine:3.22 CMD ["echo", "Selamat datang!"] $ docker run --rm say:1.0 Selamat datang! $ docker run --rm say:1.0 echo Hai Hai

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB
  • greet:1.01 layers · 12.8MB
  • say:1.01 layers · 12.8MB

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

CMD is the default order, like “the usual, please”. Say something else after the image name, and your order replaces it.

Try it

greet:1.0 uses ENTRYPOINT: The fixed command an image always runs. Words you add go after it.: a fixed first part. Run it. Then run it again with a place name at the end.

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB
  • greet:1.01 layers · 12.8MB
  • say:1.01 layers · 12.8MB

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

Predict

greet:1.0 has ENTRYPOINT ["echo", "Selamat datang ke"]. You type docker run --rm greet:1.0 Aina. What prints?

Pick one answer.

Check

Which instruction does each job?

Drag a card into a box. Or tap the card, then tap the box.

      Check

      The shout recipe writes CMD without brackets. The build works but shows a yellow warning: JSONArgsRecommended. Docker transcript: $ cat shouter/Dockerfile FROM alpine:3.22 CMD echo "Selamat datang!" $ docker build -t shout:1.0 shouter [+] Building 0.1s (5/5) FINISHED docker:default => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 81B 0.0s => WARN: JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals (line 2) => [internal] load metadata for docker.io/library/alpine:3.22 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [1/1] FROM docker.io/library/alpine:3.22@sha256:2e0b81d60597f449baa56d 0.0s => => resolve docker.io/library/alpine:3.22@sha256:2e0b81d60597f449baa56d 0.0s => exporting to image 0.1s => => exporting layers 0.0s => => exporting manifest sha256:17c0813739eb06d2466dedac6df84e320b2c6b8d1 0.0s => => exporting config sha256:26dd70318a6701e122d7ae0bb53c3b179a2872d50c4 0.0s => => exporting attestation manifest sha256:88593f1d74734ee8c332c73cc2347 0.0s => => exporting manifest list sha256:2541b0b4862ea3361151f41a258c4c86a23b 0.0s => => naming to docker.io/library/shout:1.0 0.0s => => unpacking to docker.io/library/shout:1.0 0.0s 1 warning found (use docker --debug to expand): - JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals (line 2)

      Your laptop~

      • No open hatches

      Lunchboxes (containers)

      • No containers yet

      Frozen packs (images)

      • alpine:3.221 layers · 12.9MB
      • greet:1.01 layers · 12.8MB
      • say:1.01 layers · 12.8MB

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

      Real warning: JSONArgsRecommended. Plain words: write CMD as a list in brackets. Without brackets, a shell runs your app. A stop signal may not reach it.

      You did it!

      You can now choose between CMD and ENTRYPOINT.

      Go deeper (optional)

      docker run --entrypoint whoami greet:1.0 swaps the fixed part for one run. The bracket form is called exec form. It runs your app as process 1, so docker stop reaches it quickly.

      Real mission

      1. docker build -t greet:1.0 .
      2. docker run --rm greet:1.0 Pasar Seni

      0 of 3 steps done · Your ticks are saved.