Skip to content

Instantly share code, notes, and snippets.

@roylee0704
Created December 9, 2016 08:24
Show Gist options
  • Save roylee0704/b5c8090e6cbfe1a9ae6c63062623a7cd to your computer and use it in GitHub Desktop.
Save roylee0704/b5c8090e6cbfe1a9ae6c63062623a7cd to your computer and use it in GitHub Desktop.
how to grep docker log
docker logs nginx 2>&1 | grep "127."
# ref: http://stackoverflow.com/questions/34724980/finding-a-string-in-docker-logs-of-container
@IgorOhrimenko
Copy link

Спасибо!

@gabrielponto
Copy link

thank you!

@alexvuta
Copy link

alexvuta commented Oct 6, 2020

Good job! Thanks!

@burakbengi
Copy link

👍

@BriungRi
Copy link

this is god's work 🙏

@mrsmtvd
Copy link

mrsmtvd commented Mar 5, 2021

Thank you!

@JuanCarlosV
Copy link

great thank you.

@femoru
Copy link

femoru commented Apr 22, 2021

👍

@rashidovich
Copy link

thank you.

@khenam
Copy link

khenam commented Jun 25, 2021

Thank you!

@drjasonharrison
Copy link

docker logs nginx |& grep "127."

@adeniltonbs
Copy link

Thank you!

@CollinShoop
Copy link

👍

@trevorditrani
Copy link

Thank you

@2scorpio
Copy link

2scorpio commented Mar 1, 2022

Thanks !

@cagegit
Copy link

cagegit commented Mar 9, 2022

Great!

@Vic152
Copy link

Vic152 commented Apr 1, 2022

👍

@frugan-dev
Copy link

👍

@huntersman
Copy link

Thank you

@xpufx
Copy link

xpufx commented May 27, 2022

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.

@kimegede
Copy link

kimegede commented Jun 7, 2022

Perfect! Thanks :) 👍

@rem1niscence
Copy link

👍

@QAlexBall
Copy link

👍

@AndrewCustomSumIT
Copy link

👍

@p-takagi-atilano
Copy link

👍

@athlonUA
Copy link

athlonUA commented Aug 2, 2022

👍

@davedecoder
Copy link

🍻

@tmcolby
Copy link

tmcolby commented Aug 31, 2022

thank you!

@JTejedor
Copy link

JTejedor commented Oct 31, 2022

Thanks!!!

@zsmatrix62
Copy link

牛逼!

@caublet
Copy link

caublet commented Dec 30, 2022

thanks

@stevleibelt
Copy link

Thanks

@dtlhlbs
Copy link

dtlhlbs commented Feb 26, 2023

love your work

@httpassoca
Copy link

based man

@drjasonharrison
Copy link

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

@Damon07
Copy link

Damon07 commented Jul 17, 2023

thks

@GoodbyeLittleD
Copy link

you are powerful

@CharlieUnderwood
Copy link

excellent!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! You are the one who knows "2>&1" well.

@adshrc
Copy link

adshrc commented Feb 27, 2024

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."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment