-
-
Save roylee0704/b5c8090e6cbfe1a9ae6c63062623a7cd to your computer and use it in GitHub Desktop.
docker logs nginx 2>&1 | grep "127." | |
# ref: http://stackoverflow.com/questions/34724980/finding-a-string-in-docker-logs-of-container |
👍
🍻
顶!
Thank you!
👍
Спасибо!
thank you!
Good job! Thanks!
👍
this is god's work 🙏
Thank you!
great thank you.
👍
thank you.
Thank you!
docker logs nginx |& grep "127."
Thank you!
👍
Thank you
Thanks !
Great!
👍
👍
Thank you
Whoa! Thanks! So docker logs to stdder, and then grep just passes everything in stderr through?
More like stderr is redirected to stdout. grep does what it always does afterwards.
Perfect! Thanks :) 👍
👍
👍
👍
👍
👍
🍻
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."
👍