📝 See What Your Container is Doing
Containers run in background. docker logs shows stdout/stderr output. Debug, monitor, troubleshoot.
📝 Log Commands
# View all logs docker logs container_name # Follow live logs docker logs -f container_name # Last 100 lines docker logs --tail 100 container_name # Since last 30 minutes docker logs --since 30m container_name # Since specific time docker logs --since "2024-01-15T10:00:00" container_name # Until specific time docker logs --until "2024-01-15T12:00:00" container_name # Show timestamps docker logs --timestamps container_name # Show details (log driver) docker logs --details container_name
🎯 Debugging with Logs
# Check if app started correctly docker logs --tail 50 container_name # Follow and filter docker logs -f container_name | grep ERROR # Combine with grep docker logs container_name | grep "Exception" # Export logs to file docker logs container_name > app.log 2>&1 # Check specific container (with name) docker logs web-app | head -20 # Check multiple containers docker logs web-app | tail -20 docker logs db-app | tail -20
💡 Logging Best Practices
- Log to stdout/stderr (not files)
- Set log rotation (–log-opt max-size=10m)
- Use structured logging (JSON)
- Include timestamps
- Use log aggregation in production
“docker logs is the first command for debugging. See what’s happening inside. Essential for troubleshooting.”
