World map

 

BM: Baca dalam Bahasa Melayu

World D1: First Containers

Step inside with exec

You will learn: to run commands inside a running container, and to step in with a shell.

Checked with Docker Engine 29 on 31 Oct 2026

The problem

web serves a welcome page. You want to see the files behind it. But the lunchbox is sealed. What do you do?

Pick one answer.

Watch

docker exec web ls lists two pages: 50x.html and index.html. docker exec web cat /etc/os-release shows the box runs Alpine Linux. Docker transcript: $ docker exec web ls /usr/share/nginx/html 50x.html index.html $ docker exec web cat /etc/os-release NAME="Alpine Linux" ID=alpine VERSION_ID=3.24.3 PRETTY_NAME="Alpine Linux v3.24" HOME_URL="https://alpinelinux.org/" BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"

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.

docker exec runs one command inside a running box. It is like reaching in through a side door. Then you are back on your laptop.

Try it

List the files in web’s page folder, /usr/share/nginx/html.

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.

Try it

Want to look around for longer? Build the command for a shell inside. -it gives you a keyboard and a screen in there.

Tap the pieces in the right order.

…

Try it

Step inside web. Look around with ls. Type exit to come back.

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.

Predict

Inside web you typed exit. Is web still running?

Pick one answer.

Check

Good use of exec, or not quite? Swipe each one.

Swipe right for good, left for needs work. Or use the buttons.

1 / 4

Peek at a file to check it

Peek at a file to check it

You did it!

You can now look inside a running container.

Go deeper (optional)

exec into a stopped box fails with container ... is not running. Some small images have no shell, so sh is not found (World D2). docker cp copies a file out of a box: docker cp web:/etc/nginx/nginx.conf .

Real rep (optional):

Real mission

  1. docker run -d --name web nginx:1.30-alpine
  2. docker exec -it web sh
  3. ls /usr/share/nginx/html
  4. docker rm -f web

0 of 4 steps done · Your ticks are saved.