Search code examples
dockergrep

Finding a string in docker logs of container


What is the best way to find a specific string in the logs of a docker container? Let's say I want to see all requests, that are made in the "nginx" docker image that came from a ip starting with "127."

grep wont work as expected on docker logs command:

docker logs nginx | grep "127."

It prints all logs, but does not filter the result!


Solution

  • this can happen if the container is logging to stderr, piping works only for stdout, so try:

    docker logs nginx 2>&1 | grep "127."
    
    • "2>&1" will tell the shell to redirect stderr to stdout
    • "|" to give the "unified" output to grep using pipe