Maps to Docker for Professionals - Section 9: Debugging (
docker logs,docker logs -f,docker exec,docker inspect)
When a container misbehaves in production you cannot just "open the app" - it is a
black box. Three commands are how a DevOps engineer sees inside: logs (what it is
printing), exec (run commands inside it live), and inspect (its full low-level
config). This section is a mini incident: a container is acting up, and you use these
tools to diagnose and fix it.
# from the 06-docker/ folder
make start S=05-debugging
# ...run the docker commands below in this terminal, then:
make verify S=05-debugging
make reset S=05-debuggingThe seed leaves a misbehaving container called buggy running. Save your findings
into files under 06-docker/sandbox/05-debugging/ (run the commands from the
06-docker/ folder so the relative paths line up).
1.1 (graded) The buggy container printed an error when it started. Read its logs,
find the line containing ERROR, and save that line to
sandbox/05-debugging/error.txt.
1.2 (drill) Follow the logs live with docker logs -f buggy and watch the
heartbeats arrive. Press Ctrl+C to stop following (this does not stop the
container).
2.1 (graded) Which environment does the app think it is in? Use docker exec to
read the container's environment variables, and save the APP_ENV=... line to
sandbox/05-debugging/env.txt.
2.2 (graded) Apply a live fix: use docker exec to create an (empty) file at
/tmp/fixed inside the buggy container. (This proves you can run commands in a
running container - exactly how you patch or probe one during an incident.)
Scenario: the on-call ticket needs the exact version this container was labelled with. That detail is not in the logs - it is in the container's metadata.
3.1 (graded) Use docker inspect to pull the container's version label and
save just the value to sandbox/05-debugging/version.txt.
All green = you can diagnose a container from the outside (logs, inspect) and from
the inside (exec) - the core debugging loop.
- What does
docker logs -fdo thatdocker logsdoes not? - Does pressing Ctrl+C while following logs stop the container? Why or why not?
- What is
docker execfor, and how is it different fromdocker run? - Name two things
docker inspectcan tell you that the logs cannot. - How would you open an interactive shell inside a running container?