Docker Community Forums

Share and learn in the Docker community.

Watching Logs for a specific message

I want to monitor a container log watching for specific text.
The app writes a lot of messages as it runs a process which could take anywhere from one to several hours.

ie: I’m trying to use:
docker logs mycontainer --follow

I have tried this:
docker logs mycontainer --follow --timestamps | ?{ $_ -like '*complete*' } | %{ ">>$($_)<<" }

I included the >> << in an attempt to highlight the interesting line.
It does highlight the interesting line, but there is also a lot of log messages printed that do not match '*complete*'

Possibly this is stdout -vs- stderr ?

There must be a better what of doing this. What am I missing? Help?

Yes it is. Unless you run your container with -t or --tty the log messages will be separated to the standard output and the standard error stream. docker logs keeps these streams however it reads them back from a stored json file. If you want to send everything to the standard output, you can redirect the error stream:

docker logs mycontainer --follow --timestamps 2>&1

It works on Windows too so you can do this.

docker logs mycontainer --follow --timestamps 2>&1 | ?{ $_ -like '*complete*' }