dockerdocker-logs

How to specify number of logs after each match of a particular string using docker log?


I am new to using docker-log commands. I understood how to print logs that match specific string using grep command, here is a simple example:

docker logs {dockerId} | grep "someString"

However, my goal is to per each match print the next specific number of logs.

How can I achieve this using docker log commands?


Solution

  • You can use the argument -A <n> in grep to print out <n> lines after the matched line

    docker logs {dockerId} | grep "someString" -A <number of logs>