{"id":11678,"date":"2023-08-09T09:20:00","date_gmt":"2023-08-09T01:20:00","guid":{"rendered":"http:\/\/92it.top\/?p=11678"},"modified":"2023-08-18T09:33:39","modified_gmt":"2023-08-18T01:33:39","slug":"%e4%bd%a0%e5%bf%85%e9%a1%bb%e7%9f%a5%e9%81%93%e7%9a%84%e5%ae%b9%e5%99%a8%e6%97%a5%e5%bf%97-docker-logs-logging-driver","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=11678","title":{"rendered":"\u4f60\u5fc5\u987b\u77e5\u9053\u7684\u5bb9\u5668\u65e5\u5fd7 Docker logs &#038; logging driver"},"content":{"rendered":"\n<p>\u8f6c\u8f7d\uff1a<a href=\"https:\/\/www.cnblogs.com\/edisonchou\/p\/docker_logs_study_summary_part1.html\">https:\/\/www.cnblogs.com\/edisonchou\/p\/docker_logs_study_summary_part1.html<\/a><\/p>\n\n\n\n<p>\u672c\u7bc7\u5df2\u52a0\u5165\u300a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.cnblogs.com\/edisonchou\/p\/aspnet_core_k8s_artcles_index.html\" target=\"_blank\">.NET Core on K8S\u5b66\u4e60\u5b9e\u8df5\u7cfb\u5217\u6587\u7ae0\u7d22\u5f15<\/a>\u300b\uff0c\u53ef\u4ee5\u70b9\u51fb\u67e5\u770b\u66f4\u591a\u5bb9\u5668\u5316\u6280\u672f\u76f8\u5173\u7cfb\u5217\u6587\u7ae0\u3002\u76d1\u63a7\u548c\u65e5\u5fd7\u5386\u6765\u90fd\u662f\u7cfb\u7edf\u7a33\u5b9a\u8fd0\u884c\u548c\u95ee\u9898\u6392\u67e5\u7684\u5173\u952e\uff0c\u5728\u5fae\u670d\u52a1\u67b6\u6784\u4e2d\uff0c\u6570\u91cf\u4f17\u591a\u7684\u5bb9\u5668\u4ee5\u53ca\u5feb\u901f\u53d8\u5316\u7684\u7279\u6027\u4f7f\u5f97\u4e00\u5957\u96c6\u4e2d\u5f0f\u7684\u65e5\u5fd7\u7ba1\u7406\u7cfb\u7edf\u53d8\u6210\u4e86\u751f\u4ea7\u73af\u5883\u4e2d\u4e00\u4e2a\u4e0d\u53ef\u83b7\u53d6\u7684\u90e8\u5206\u3002\u6b64\u6b21\u8bdd\u9898\u6211\u4eec\u4f1a\u96c6\u4e2d\u5728\u65e5\u5fd7\u7ba1\u7406\u65b9\u9762\uff0c\u672c\u7bc7\u4f1a\u4ecb\u7ecdDocker\u81ea\u5e26\u7684logs\u5b50\u547d\u4ee4\u4ee5\u53ca\u5176Logging driver\u3002<\/p>\n\n\n\n<p><strong>\u4e00\u3001Docker logs\u5b50\u547d\u4ee4<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cDocker\u7684\u65e5\u5fd7\u4f1a\u53d1\u9001\u5230\u5bb9\u5668\u7684\u6807\u51c6\u8f93\u51fa\u8bbe\u5907\uff08STDOUT\uff09\u548c\u6807\u51c6\u9519\u8bef\u8bbe\u5907\uff08STDERR\uff09\uff0c\u5176\u4e2dSTDOUT\u548cSTDERR\u5b9e\u9645\u4e0a\u5c31\u662f\u5bb9\u5668\u7684\u63a7\u5236\u53f0\u7ec8\u7aef\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7logs\u5b50\u547d\u4ee4\u6765\u67e5\u770b\u5177\u4f53\u67d0\u4e2a\u5bb9\u5668\u7684\u65e5\u5fd7\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker logs edc-k8s-demo<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-18-1024x206.png\" alt=\"\" class=\"wp-image-11679\" width=\"507\" height=\"101\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-18-1024x206.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-18-300x60.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-18-768x154.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-18-830x167.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-18-230x46.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-18-350x70.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-18-480x96.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-18.png 1294w\" sizes=\"(max-width: 507px) 100vw, 507px\" \/><\/figure><\/div>\n\n\n\n<p>\u8fd9\u65f6\u770b\u5230\u7684\u65e5\u5fd7\u662f\u9759\u6001\u7684\uff0c\u622a\u6b62\u5230\u76ee\u524d\u4e3a\u6b62\u7684\u65e5\u5fd7\u3002\u5982\u679c\u60f3\u8981\u6301\u7eed\u770b\u5230\u65b0\u6253\u5370\u51fa\u7684\u65e5\u5fd7\u4fe1\u606f\uff0c\u90a3\u4e48\u53ef\u4ee5\u52a0\u4e0a -f \u53c2\u6570\uff0c\u5982\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker logs -f edc-k8s-demo<\/pre>\n\n\n\n<p><strong>\u4e8c\u3001Docker logging driver<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u521a\u521a\u6211\u4eec\u5b66\u4e60\u4e86\u9ed8\u8ba4\u914d\u7f6e\u4e0b\uff0cDocker\u65e5\u5fd7\u4f1a\u53d1\u9001\u5230STDOUT\u548cSTDERR\u3002\u4f46\u5b9e\u9645\u4e0a\uff0cDocker\u8fd8\u63d0\u4f9b\u4e86\u5176\u4ed6\u7684\u4e00\u4e9b\u673a\u5236\u5141\u8bb8\u6211\u4eec\u4ece\u8fd0\u884c\u7684\u5bb9\u5668\u4e2d\u63d0\u53d6\u65e5\u5fd7\uff0c\u8fd9\u4e9b\u673a\u5236\u7edf\u79f0\u4e3a logging driver\u3002<\/p>\n\n\n\n<p>\u5bf9Docker\u800c\u8a00\uff0c\u5176\u9ed8\u8ba4\u7684logging driver\u662fjson-file\uff0c\u5982\u679c\u5728\u542f\u52a8\u65f6\u6ca1\u6709\u7279\u522b\u6307\u5b9a\uff0c\u90fd\u4f1a\u4f7f\u7528\u8fd9\u4e2a\u9ed8\u8ba4\u7684logging driver\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-19-1024x96.png\" alt=\"\" class=\"wp-image-11680\" width=\"561\" height=\"52\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-19-1024x96.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-19-300x28.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-19-768x72.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-19-830x78.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-19-230x22.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-19-350x33.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-19-480x45.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-19.png 1216w\" sizes=\"(max-width: 561px) 100vw, 561px\" \/><\/figure><\/div>\n\n\n\n<p>json-file\u4f1a\u5c06\u6211\u4eec\u5728\u63a7\u5236\u53f0\u901a\u8fc7docker logs\u547d\u540d\u770b\u5230\u7684\u65e5\u5fd7\u90fd\u4fdd\u5b58\u5728\u4e00\u4e2ajson\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u670d\u52a1\u5668Host\u4e0a\u7684\u5bb9\u5668\u76ee\u5f55\u4e2d\u627e\u5230\u8fd9\u4e2ajson\u6587\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u5bb9\u5668\u65e5\u5fd7\u8def\u5f84\uff1a\/var\/lib\/docker\/containers\/&lt;container-id>\/&lt;container-id>-json.log<\/pre>\n\n\n\n<p>\u4f8b\u5982\u6211\u4eec\u53ef\u4ee5\u67e5\u770b\u4e00\u4e2aexceptionless-api\u5bb9\u5668\u7684json\u65e5\u5fd7\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-20-1024x554.png\" alt=\"\" class=\"wp-image-11681\" width=\"511\" height=\"276\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-20-1024x554.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-20-300x162.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-20-768x415.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-20-830x449.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-20-230x124.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-20-350x189.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-20-480x260.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-20.png 1220w\" sizes=\"(max-width: 511px) 100vw, 511px\" \/><\/figure><\/div>\n\n\n\n<p>\u4e00\u4e2a\u5feb\u901f\u67e5\u770b\u67d0\u4e2a\u5bb9\u5668\u7684\u65e5\u5fd7\u6587\u4ef6\u8def\u5f84\u7684\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker inspect exceptionless_api_1<\/pre>\n\n\n\n<p>\u901a\u8fc7inspect\u547d\u4ee4\uff0c\u53ef\u4ee5\u67e5\u5230\u8be5\u5bb9\u5668\u7684ID\u53ca\u4e00\u7cfb\u5217\u914d\u7f6e\u4fe1\u606f\uff0c\u6211\u4eec\u91cd\u70b9\u5173\u6ce8LogPath\u5373\u53ef\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-21-1024x234.png\" alt=\"\" class=\"wp-image-11682\" width=\"610\" height=\"138\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-21-1024x234.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-21-300x68.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-21-768x175.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-21-830x189.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-21-230x52.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-21-350x80.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-21-480x110.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-21.png 1306w\" sizes=\"(max-width: 610px) 100vw, 610px\" \/><\/figure><\/div>\n\n\n\n<p>\u67e5\u5230LogPath\u540e\uff0c\u5373\u53ef\u590d\u5236\u5176\u540e\u9762\u7684\u65e5\u5fd7\u8def\u5f84\u4e86\uff0c\u6253\u5f00\u8fd9\u4e2ajson\u6587\u4ef6\u4f60\u5c31\u53ef\u4ee5\u770b\u5230\u8f93\u51fa\u7684\u5bb9\u5668\u65e5\u5fd7\u4e86\u3002<\/p>\n\n\n\n<p>\u9664\u4e86json-file\uff0cDocker\u8fd8\u652f\u6301\u4ee5\u4e0b\u591a\u79cdlogging dirver\uff0c\u6765\u6e90\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/docs.docker.com\/config\/containers\/logging\/configure\/\" target=\"_blank\">Configure logging drivers<\/a><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-22-976x1024.png\" alt=\"\" class=\"wp-image-11683\" width=\"511\" height=\"536\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-22-976x1024.png 976w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-22-286x300.png 286w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-22-768x806.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-22-830x871.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-22-230x241.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-22-350x367.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-22-480x504.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-22.png 1340w\" sizes=\"(max-width: 511px) 100vw, 511px\" \/><\/figure><\/div>\n\n\n\n<p>\u5176\u4e2d\uff0cnone \u4ee3\u8868\u7981\u7528\u5bb9\u5668\u65e5\u5fd7\uff0c\u4e0d\u4f1a\u8f93\u51fa\u4efb\u4f55\u5bb9\u5668\u65e5\u5fd7\u3002<\/p>\n\n\n\n<p>\u5176\u4ed6\u51e0\u4e2alogging driver\u89e3\u91ca\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul><li>syslog \u4e0e journald \u662fLinux\u4e0a\u7684\u4e24\u79cd\u65e5\u5fd7\u7ba1\u7406\u670d\u52a1<\/li><li>awslog\u3001splunk \u4e0e gcplogs\u662f\u7b2c\u4e09\u65b9\u65e5\u5fd7\u6258\u7ba1\u670d\u52a1<\/li><li>gelf \u4e0e fluentd \u662f\u4e24\u79cd\u5f00\u6e90\u7684\u65e5\u5fd7\u7ba1\u7406\u65b9\u6848<\/li><\/ul>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u5728\u5bb9\u5668\u542f\u52a8\u65f6\u901a\u8fc7\u52a0\u4e0a &#8211;log-driver \u6765\u6307\u5b9a\u4f7f\u7528\u54ea\u4e2a\u5177\u4f53\u7684 logging driver\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker run -d --log-driver=syslog ......<\/pre>\n\n\n\n<p>\u5982\u679c\u60f3\u8981\u8bbe\u7f6e\u9ed8\u8ba4\u7684logging driver\uff0c\u90a3\u4e48\u5219\u9700\u8981\u4fee\u6539Docker daemon\u7684\u542f\u52a8\u811a\u672c\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  \"log-driver\": \"json-file\",\n  \"log-opts\": {\n    \"labels\": \"production_status\",\n    \"env\": \"os,customer\"\n  }\n}<\/pre>\n\n\n\n<p>\u6bcf\u4e2alogging driver\u90fd\u6709\u4e00\u4e9b\u81ea\u5df1\u7279\u5b9a\u7684log-opt\uff0c\u4f7f\u7528\u65f6\u53ef\u4ee5\u53c2\u8003\u5177\u4f53\u5b98\u65b9\u6587\u6863\u3002<\/p>\n\n\n\n<p><strong>\u4e09\u3001\u5c0f\u7ed3<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u672c\u6587\u4ecb\u7ecd\u4e86Docker\u81ea\u5e26\u7684logs\u5b50\u547d\u4ee4\u4ee5\u53calogging driver\uff0c\u9ed8\u8ba4\u7684logging driver\u662fjson-file\uff0c\u5f53\u7136Docker\u8fd8\u652f\u6301\u591a\u4e2a\u4e0d\u540c\u673a\u5236\u7684logging dirver\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u5728\u4f7f\u7528\u65f6\u8fdb\u884c\u6307\u5b9a\u3002\u4e0b\u4e00\u7bc7\uff0c\u6211\u4eec\u4f1a\u5b66\u4e60\u6d41\u884c\u7684\u5f00\u6e90\u65e5\u5fd7\u7ba1\u7406\u4e09\u5144\u5f1fELK\uff08ElasticSearch\u3001Logstash\u3001Kibana\uff09\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u8f7d\uff1ahttps:\/\/www.cnblogs.com\/edisonchou\/p\/docker_logs_stu [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11678"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11678"}],"version-history":[{"count":2,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11678\/revisions"}],"predecessor-version":[{"id":11933,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11678\/revisions\/11933"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}