Logging & Resources

Logs

  • Write logs to stdout/stderr, not files inside the container; Docker collects them.
  • Limit log size so disks do not fill up: --log-opt max-size=10m --log-opt max-file=3.
  • In the cloud, logs go to the platform (Cloud Logging, CloudWatch) automatically.
  • Prefer structured JSON logs so they can be searched and filtered.

CPU and Memory Limits

Example

docker run -d --name api --memory 512m --cpus 1.5 myapi:1.0
docker stats --no-stream api

Example output

CONTAINER ID   NAME   CPU %   MEM USAGE / LIMIT   MEM %
a1b2c3d4e5f6   api    0.35%   84.2MiB / 512MiB    16.45%

Note: A container that exceeds its memory limit is killed (exit code 137, "OOMKilled"). Set limits based on measured usage plus headroom.