Grepping Docker Logs

May 4, 2018

Some of the things in docker logs are written to stdout and others to stderr. If you grep like this:

$ docker logs my-docker-container | grep "Thing that doesn't exist in the file"

The output will show any lines from the docker log that were written to stderr. This may be confusing.

To change this behaviour, you can redirect stderr to stdout like this:

$ docker logs my-docker-container 2>&1 | grep "Thing that doesn't exist in the file"

In this, the 2 refers to stderr and 1 to stdout. The >& appends everything from stderr to stdout.