By default Docker keeps container output in a JSON file that grows without limit. Set rotation globally in /etc/docker/daemon.json:
{
"log-driver": "json-file",
"log-opts": { "max-size": "10m", "max-file": "3" }
}
sudo systemctl restart docker # applies to newly created containers
docker logs --tail 100 -f web
Then limit resources so a runaway process cannot starve its neighbours:
docker run -d --name api \
--memory 512m --memory-swap 512m --cpus 1.5 \
--restart unless-stopped myapp:1.0
docker stats --no-stream
A container that exceeds its memory limit is killed by the kernel (OOMKilled in docker inspect). Write logs to stdout and stderr, not to files inside the container, so Docker collects them. For several hosts, ship logs with a driver such as awslogs to CloudWatch.