Przejdลบ do treล›ci

๐Ÿ“œ Docker Logs

Documentation covering log inspection, troubleshooting and best practices for working with container logs in Docker and Docker Compose.


๐Ÿš€ Essential Commands

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Logs for a specific container
docker logs <container_name>

# Live logs (follow mode)
docker logs -f <container_name>

# Show last N lines
docker logs --tail 200 <container_name>

# Logs with timestamps
docker logs -t <container_name>

๐Ÿงฉ Logs in Docker Compose

1
2
3
4
5
6
7
8
# Live logs for all services
docker compose logs -f

# Live logs for a specific service
docker compose logs -f app

# Last N lines for a service
docker compose logs --tail 100 app

๐Ÿ› ๏ธ Debugging & Diagnostics

1
2
3
4
5
# Check container exit code
docker inspect --format='{{.State.ExitCode}}' <container>

# Full container metadata
docker inspect <container_name>

Useful for identifying:

  • crash loops
  • healthcheck failures
  • permission issues
  • missing environment variables

๐Ÿง  Best Practices

  • Always log to stdout and stderr
  • Avoid writing logs to files inside the container
  • Use structured logging (JSON) for production systems
  • Ensure log output is not excessively verbose
  • Use log drivers (e.g., json-file, syslog, loki) when needed
  • Rotate logs on the host to avoid disk pressure

๐Ÿ“˜ Additional Topics