Docker Logs & Debugging
Monitoring and debugging are essential when working with Docker containers. Docker provides built-in commands to view logs, inspect containers, and troubleshoot issues efficiently.
View Container Logs
# View logs of a container
docker logs my-container
# Follow logs in real-time
docker logs -f my-container
# Show last 50 lines
docker logs --tail 50 my-container
# Show logs with timestamps
docker logs -t my-container
Check Running Containers
docker ps
To see all containers (including stopped):
docker ps -a
Inspect Container Details
docker inspect my-container
This shows detailed information like IP address, mounts, environment variables, and configuration.
Execute Commands Inside Container
# Open bash shell
docker exec -it my-container bash
# Run a single command
docker exec my-container ls
Check Resource Usage
docker stats
This shows CPU, memory, and network usage for running containers.
View Container Processes
docker top my-container
Debugging Common Issues
- Container not starting: Check logs using
docker logs - Port not accessible: Verify port mapping with
-p - App crash: Check environment variables and dependencies
- Permission issues: Verify file permissions inside container
Restart & Remove Containers
# Restart container
docker restart my-container
# Stop container
docker stop my-container
# Remove container
docker rm my-container
Debug with Docker Compose
# View logs of all services
docker compose logs
# Follow logs
docker compose logs -f
# Logs of specific service
docker compose logs app
Summary
- Use
docker logsto monitor container output. - Use
docker execto debug inside containers. - Use
docker inspectfor detailed configuration. - Use
docker statsto monitor performance.
0
likes
Your Feedback
Help us improve by sharing your thoughts
Online Learner helps developers master programming, database concepts, interview preparation, and real-world implementation through structured learning paths.
Quick Links
© 2023 - 2026 OnlineLearner.in | All Rights Reserved.
