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
Your laptop~
- Laptop port 8080 → web port 80
Lunchboxes (containers)
- webrunning
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
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.
Hint
docker exec web ls /usr/share/nginx/htmlTry 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
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.
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
docker run -d --name web nginx:1.30-alpinedocker exec -it web shls /usr/share/nginx/htmldocker rm -f web
0 of 4 steps done · Your ticks are saved.
Bahasa Melayu
web hidangkan halaman selamat datang. Anda mahu tengok fail di sebaliknya. Tapi bekas itu bertutup. Apa anda buat?
docker exec jalankan satu arahan dalam bekas yang berjalan. Macam capai melalui pintu tepi. Kemudian anda kembali ke laptop.
Senaraikan fail dalam folder halaman web, /usr/share/nginx/html.
docker exec web ls /usr/share/nginx/htmlMahu tengok-tengok lebih lama? Bina arahan untuk shell di dalam. -it beri anda papan kekunci dan skrin di situ.
Masuk ke dalam web. Tengok-tengok dengan ls. Taip exit untuk kembali.
Di dalam web anda taip exit. Adakah web masih berjalan?
Cara guna exec yang bagus, atau belum tepat? Leret setiap satu.
Kini anda boleh tengok ke dalam container yang sedang berjalan.
You finished this before. Practice is always welcome!
Official docs: docker exec · docker cp
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?