Troubleshooting & Logs

Difficulty: Beginner

Question

How do you troubleshoot a container that starts and immediately exits?

Answer

1. **Check Logs**: `docker logs <container_id>` is the first step. 2. **Inspect**: `docker inspect` to see exit codes and status. 3. **Override Command**: Try running with an interactive shell: `docker run -it my-image /bin/sh` to manually test the environment.

Code examples

Viewing logs

# Tailing logs to see issues in real-time
docker logs -f --tail 100 my-app

-f follows the log, --tail 100 shows the last 100 lines.

Key points

Concepts covered

CLI, Logs, Debugging