World map

 

BM: Baca dalam Bahasa Melayu

World D1: First Containers

Follow the logs

You will learn: to read what a container printed, and to watch new lines live.

Checked with Docker Engine 29 on 31 Oct 2026

The problem

docker ps -a lists two boxes. web is Up. timer shows Exited (127). Docker transcript: $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d087a93072c4 alpine:3.22 "sh -c 'echo Timer o…" 6 seconds ago Exited (127) 6 seconds ago timer 09d2de506559 nginx:1.30-alpine "/docker-entrypoint.…" 9 seconds ago Up 9 seconds 0.0.0.0:8080->80/tcp web

Your laptop~

  • Laptop port 8080 → web port 80

Lunchboxes (containers)

  • webrunning
    from nginx:1.30-alpine 8080→80
  • timerfailed (exit 127)
    from alpine:3.22

Frozen packs (images)

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

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

Your timer box should tick for an hour. It stopped at once: Exited (127). No error on your screen. How do you find out why?

Try it

A box keeps notes of everything it prints: its logs: Everything a container printed while it worked. Read them with docker logs.. Read timer’s notes.

Your laptop~

  • Laptop port 8080 → web port 80

Lunchboxes (containers)

  • webrunning
    from nginx:1.30-alpine 8080→80
  • timerfailed (exit 127)
    from alpine:3.22

Frozen packs (images)

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

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

Check

The logs end with the real error sh: sleeep: not found. What does it mean?

Pick one answer.

Watch

curl visits web. Then docker logs --tail 1 web shows one new line: a GET request with status 200. Docker transcript: $ curl -s localhost:8080 | grep title <title>Welcome to nginx!</title> $ docker logs --tail 1 web 172.17.0.1 - - [31/Oct/2026:01:00:12 +0000] "GET / HTTP/1.1" 200 896 "-" "curl/8.5.0" "-"

Your laptop~

  • Laptop port 8080 → web port 80

Lunchboxes (containers)

  • webrunning
    from nginx:1.30-alpine 8080→80
  • timerfailed (exit 127)
    from alpine:3.22

Frozen packs (images)

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

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

Every visit to web adds a line. --tail 1 shows only the last one. Add -f (follow) to watch new lines live. Ctrl+C stops watching.

Try it

Visit web with curl localhost:8080. Then read web’s logs and find your visit.

Your laptop~

  • Laptop port 8080 → web port 80

Lunchboxes (containers)

  • webrunning
    from nginx:1.30-alpine 8080→80
  • timerfailed (exit 127)
    from alpine:3.22

Frozen packs (images)

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

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

Predict

docker logs -f web is running. You press Ctrl+C. What happens to web?

Pick one answer.

You did it!

You can now read a container’s logs to find the problem.

Go deeper (optional)

Logs are what the app prints to the screen (stdout and stderr). The nginx image sends its log files there too. Handy flags: --tail 20, --since 10m, and -t for times. Logs vanish when you remove the box.

Real rep (optional):

Real mission

  1. docker run -d --name web -p 8080:80 nginx:1.30-alpine
  2. docker logs -f web
  3. docker rm -f web

0 of 4 steps done · Your ticks are saved.