Finding a string in docker logs of container

前端 未结 8 1055
南方客
南方客 2021-01-30 01:21

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 fr

相关标签:
8条回答
  • 2021-01-30 02:06

    First, use this command ( b1e3c456f07f is the container id ):

    docker inspect --format='{{.LogPath}}' b1e3c456f07f
    

    The result will be something like this:

    /var/lib/docker/containers/b1e3c456f07f2cb3ae79381ada33a034041a10f65174f52bc1792110b36fb767/b1e3c456f07f2cb3ae79381ada33a034041a10f65174f52bc1792110b36fb767-json.log
    

    Second, use this command ( you can use vim if you like ):

    nano /var/lib/docker/containers/b1e3c456f07f2cb3ae79381ada33a034041a10f65174f52bc1792110b36fb767/b1e3c456f07f2cb3ae79381ada33a034041a10f65174f52bc1792110b36fb767-json.log
    
    0 讨论(0)
  • 2021-01-30 02:15

    I generally use it with -f option as well, when I am debugging the issue

    docker logs -f nginx 2>&1 | grep "127."
    

    It will show us, what we are expecting in real-time.

    0 讨论(0)
提交回复
热议问题