World map

 

BM: Baca dalam Bahasa Melayu

World D1: First Containers

Handy run flags: -d, --name, --rm

You will learn: to run a container in the background, give it a name, and let it tidy up.

Checked with Docker Engine 29 on 31 Oct 2026

The problem

docker run nginx:1.30-alpine. nginx starts in front of you. Its messages fill the terminal and the prompt does not come back. The new box got a random name. Docker transcript: $ docker run nginx:1.30-alpine /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh 10-listen-on-ipv6-by-default.sh: info: ipv6 not available /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh /docker-entrypoint.sh: Configuration complete; ready for start up 2026/10/31 01:00:03 [notice] 1#1: using the "epoll" event method 2026/10/31 01:00:03 [notice] 1#1: nginx/1.30.6 2026/10/31 01:00:03 [notice] 1#1: built by gcc 15.2.0 (Alpine 15.2.0) 2026/10/31 01:00:03 [notice] 1#1: OS: Linux 6.18.44-fc-v185 2026/10/31 01:00:03 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576 2026/10/31 01:00:03 [notice] 1#1: start worker processes 2026/10/31 01:00:03 [notice] 1#1: start worker process 20 2026/10/31 01:00:03 [notice] 1#1: start worker process 21 2026/10/31 01:00:03 [notice] 1#1: start worker process 22 2026/10/31 01:00:03 [notice] 1#1: start worker process 23

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB
  • nginx:1.30-alpine8 layers · 93.5MB

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

You ran nginx. Now your terminal is stuck, full of messages. And the box got a random name. Let’s fix both.

Try it

Build a better command. detached (-d): The container runs in the background, like a rice cooker: press start, walk away. means detached. The box runs in the background, like a rice cooker. --name picks its name.

Tap the pieces in the right order.

…

Try it

Now type it. Your terminal stays free, and the box is called web.

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB
  • nginx:1.30-alpine8 layers · 93.5MB

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

Watch

docker run --rm alpine:3.22 echo hi prints hi. Then docker ps -a shows an empty list: the box threw itself away. Docker transcript: $ docker run --rm alpine:3.22 echo hi hi $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB
  • nginx:1.30-alpine8 layers · 93.5MB

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

–rm throws the box away when its job ends. docker ps -a shows nothing left. Perfect for one-off jobs.

Try it

Which flag fits each job?

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

        Predict

        web already exists. You run docker run -d --name web nginx:1.30-alpine again. What happens?

        Pick one answer.

        Check

        A box called web already runs. docker run --name web answers with a Conflict error: the name is already in use. Docker transcript: $ docker run -d --name web nginx:1.30-alpine docker: Error response from daemon: Conflict. The container name "/web" is already in use by container "6ec55477bc83e265efff898782c9659842ae83490bf5db2bc364ef5396b65203". You have to remove (or rename) that container to be able to reuse that name. Run 'docker run --help' for more information

        Your laptop~

        • Laptop port 8080 → web port 80

        Lunchboxes (containers)

        • webrunning
          from nginx:1.30-alpine 8080→80

        Frozen packs (images)

        • alpine:3.221 layers · 12.9MB
        • nginx:1.30-alpine8 layers · 93.5MB · in use

        1 containers (1 running), 2 images, 0 lockers.

        The real error says the name "/web" is already in use. Plain words: one name, one box. Remove the old box, or pick a new name.

        You did it!

        You can now run, name and tidy up boxes with three flags.

        Go deeper (optional)

        -d and --rm work together: a background box that cleans up when it stops. docker rename web shop changes a name. -it gives you a keyboard inside a box; that comes in lesson 6.

        Real rep (optional):

        Real mission

        1. docker run -d --name web nginx:1.30-alpine
        2. docker run --rm alpine:3.22 echo hi
        3. docker ps -a
        4. docker rm -f web

        0 of 4 steps done · Your ticks are saved.