Course contentsShow
← Software Engineering
Lesson 1441 of 1,93342. Containerization and OrchestrationFree lesson

Debugging and Inspecting Running Containers

Use Docker commands to inspect logs, execute commands inside containers, and troubleshoot runtime issues effectively.

Debugging and Inspecting Running Containers

What you'll learn: How to diagnose and troubleshoot issues in running containers using Docker's inspection and debugging commands.

Why Debugging Containers Is Different

When your containerized application misbehaves, you can't just open Task Manager or SSH in like a traditional server. Containers are ephemeral, isolated environments—think of them as sealed boxes running your app. You need specialized tools to peek inside without breaking the seal.

Core Debugging Commands

Viewing Container Logs

The docker logs command streams stdout and stderr from your container:

docker logs <container-id>
docker logs -f <container-id>  # Follow logs in real-time
docker logs --tail 100 <container-id>  # Last 100 lines

This is your first line of defense—most issues announce themselves through logs.

Executing Commands Inside Containers

When logs aren't enough, use docker exec to run commands inside a running container:

docker exec -it <container-id> /bin/bash
docker exec <container-id> ps aux  # Check running processes
docker exec <container-id> cat /app/config.yml  # Inspect files

The -it flags give you an interactive terminal session—like stepping inside the box.

Inspecting Container Details

The docker inspect command reveals everything about a container's configuration:

docker inspect <container-id>
docker inspect --format='{{.State.Status}}' <container-id>

This shows network settings, environment variables, mounted volumes, resource limits, and more.

Checking Resource Usage

Monitor real-time resource consumption:

docker stats <container-id>

Key Takeaway: Effective container debugging combines docker logs for application output, docker exec for interactive investigation, and docker inspect for configuration details—giving you complete visibility into running containers without traditional server access.