How to redirect docker logs with grep command to a text file? [duplicate] How to redirect docker logs with grep command to a text file? [duplicate] docker docker

How to redirect docker logs with grep command to a text file? [duplicate]


As per the anemyte's comment, --line-buffered with grep command fixed my problem. The final command is,

docker logs -f docker_container 2>&1 | grep --line-buffered "KafkaRecordGenerator:197" >> test.txt