Created
December 9, 2016 08:24
-
-
Save roylee0704/b5c8090e6cbfe1a9ae6c63062623a7cd to your computer and use it in GitHub Desktop.
how to grep docker log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker logs nginx 2>&1 | grep "127." | |
# ref: http://stackoverflow.com/questions/34724980/finding-a-string-in-docker-logs-of-container |
👍
👍
👍
👍
👍
🍻
thank you!
Thanks!!!
牛逼!
thanks
Thanks
love your work
based man
More flexible, take the container ID as the first argument, and pass remaining arguments to grep
#!/usr/bin/env bash
#
# Docker outputs logs to stderr not stdout, redirect output for the specified container and
# pass remaining arguments to grep
#
# Usage:
# dockergrep.bash [container ID] -i error
# dockergrep.bash [container name] 127.
# dockergrep.bash [container name] -C 3 Successfully
#
docker logs "$1" 2>&1 | grep "${@:2}"
# ref: http://stackoverflow.com/questions/34724980/finding-a-string-in-docker-logs-of-container
thks
you are powerful
excellent!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! You are the one who knows "2>&1" well.
if you get "grep: (standard input): binary file matches" error, when doing e.g. --since=48h, try this:
docker logs nginx 2>&1 | grep -a "127."
Thanks!
Thanks!
Thanks
thanks
Thanks!
Gracias!
wow, the same level as Alan Turing. Thanks
thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perfect! Thanks :) 👍