docker logs — view container output

# View all logs
docker logs my-container

# Follow (stream) live logs
docker logs -f my-container

# Last 100 lines only
docker logs --tail 100 my-container

# With timestamps
docker logs -t my-container

You need to see what a container printed to stdout/stderr — for debugging crashes, startup errors, or request logs.

Logs since a time or duration

# Logs from the last 30 minutes
docker logs --since 30m my-container

# Since an absolute timestamp
docker logs --since "2024-01-15T10:00:00" my-container

# Between two times
docker logs --since "2024-01-15T09:00:00" --until "2024-01-15T10:00:00" my-container

Logs from a stopped container

# Works the same way — container does not need to be running
docker ps -a   # find the container ID
docker logs <container-id>

Configure log driver and size limit

By default Docker uses the json-file driver. Limit size to avoid disk exhaustion:

# docker run
docker run --log-opt max-size=10m --log-opt max-file=3 my-image

# daemon-wide default in /etc/docker/daemon.json
{
  "log-driver": "json-file",
  "log-opts": { "max-size": "10m", "max-file": "3" }
}