docker/logs

View Logs

Fetch logs from a container’s stdout and stderr.

container
debugging

Command

docker logs

Explanation

docker logs retrieves the standard output and error streams of containers. It’s critical for debugging issues. Use -f to follow output live and --tail for limiting the number of lines shown.

Common Use Cases

  • Monitor application output
  • Debug container startup failures
  • Stream logs for observability tools

Best Practices

  • Use -f for active monitoring
  • Pipe logs to analysis tools

Common Mistakes to Avoid

  • Running docker logs on non-existent or stopped containers without -a

Troubleshooting

Problem: No logs appear

Solution: Ensure container was started correctly; some base images log to files inside container instead of stdout.

Examples

Show container logs

docker logs my_container

Follow logs in real time

docker logs -f my_container