How can I both tail and grep Docker logs? I've tried the following:
sudo docker logs -f my_container | grep foo
This should tail all lines with foo
from the container's logs, but instead shows everything.
Here's what I did:
sudo docker logs -f my_container &> log.log & tail -f log.log | grep foo
docker logs -f my_container &> log.log
tails all the containers logs while also outputting to file log.log
. In parallel, which is what the &
by itself does, tail -f log.log | grep foo
tails that file and greps, which a common way to grep tailed output.
The downside is that file log.log
is created, but there was no other way to do this.