>_ IzzyLab

Topic breakdown

Docker keeps everything the container's main process writes to stdout and stderr — that's the container's log. That's why applications in containers write logs straight to the screen rather than to files.

docker logs api              # the whole log
docker logs --tail 20 api    # the last 20 lines
docker logs -f api           # follow new lines, Ctrl+C to quit
docker logs -t api           # with timestamps

The log is available for a stopped container too — until it's removed. docker logs keeps the streams apart: what the container wrote to stderr goes out to stderr. This matters for | and >: by default they take only stdout, and 2>&1 adds stderr.

What's checked

  1. /root/last.txt has the last 5 lines of the log
  2. /root/error.txt has the line with ERROR

What it looks like