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!
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 tells the shell to redirect stderr to stdout and give the output to grep using pipe.
As vim fan I prefer to use less
and search with /
docker logs nginx 2>&1 | less
docker logs <container_name> 2>&1 | grep <string>