Debugging ContainersAdvanced
1Question 1 of 1
bash

How do you inspect and debug running containers?

Explanation & Concept

Essential debugging commands: • `docker logs -f <container>`: Stream application stdout/stderr logs. • `docker exec -it <container> sh`: Open an interactive shell inside a running container. • `docker inspect <container>`: View low-level configuration, network IPs, and health check history. • `docker stats`: Monitor real-time CPU, RAM, and network I/O usage.

Code Example
bash
# Inspect container exit code and error state
docker inspect --format='{{.State.ExitCode}}: {{.State.Error}}' my_failed_container
How It Works & Key Takeaways

Formatting `docker inspect` with Go templates allows extracting exact error states and IP addresses without scrolling through megabytes of JSON.