{"id":13628,"date":"2024-11-15T20:04:26","date_gmt":"2024-11-15T12:04:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/13628\/"},"modified":"2024-11-15T20:04:26","modified_gmt":"2024-11-15T12:04:26","slug":"docker%e6%95%85%e9%9a%9c%e7%a0%81%e5%92%8c%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95-error-memory-limit-exceeded","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/13628\/","title":{"rendered":"Docker\u6545\u969c\u7801\u548c\u89e3\u51b3\u529e\u6cd5 &#8211; Error: memory limit exceeded"},"content":{"rendered":"<h1 id=\"docker%e6%95%85%e9%9a%9c%e7%a0%81%e5%92%8c%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95-error-memory-limit-exceeded-ccWjpPlCOK\">Docker\u6545\u969c\u7801\u548c\u89e3\u51b3\u529e\u6cd5 &#8211; Error: memory limit exceeded<\/h1>\n<p>\u5728\u4f7f\u7528Docker\u5bb9\u5668\u65f6\uff0c\u5f00\u53d1\u8005\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u9519\u8bef\u7801\uff0c\u5176\u4e2d\u201cmemory limit exceeded\u201d\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u95ee\u9898\u3002\u8fd9\u4e00\u9519\u8bef\u901a\u5e38\u8868\u793a\u5bb9\u5668\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u8d85\u51fa\u4e86\u5206\u914d\u7ed9\u5b83\u7684\u5185\u5b58\u9650\u5236\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u8fd9\u4e00\u9519\u8bef\u7684\u539f\u56e0\u3001\u5f71\u54cd\u4ee5\u53ca\u89e3\u51b3\u529e\u6cd5\u3002<\/p>\n<h2 id=\"%e4%bb%80%e4%b9%88%e6%98%afmemory-limit-exceeded%e9%94%99%e8%af%af%ef%bc%9f-ccWjpPlCOK\">\u4ec0\u4e48\u662f\u201cmemory limit exceeded\u201d\u9519\u8bef\uff1f<\/h2>\n<p>\u5f53Docker\u5bb9\u5668\u88ab\u5206\u914d\u4e86\u7279\u5b9a\u7684\u5185\u5b58\u9650\u5236\u65f6\uff0c\u5982\u679c\u5bb9\u5668\u5185\u7684\u5e94\u7528\u7a0b\u5e8f\u5c1d\u8bd5\u4f7f\u7528\u8d85\u8fc7\u8be5\u9650\u5236\u7684\u5185\u5b58\uff0c\u5c31\u4f1a\u89e6\u53d1\u201cmemory limit exceeded\u201d\u9519\u8bef\u3002\u8fd9\u79cd\u60c5\u51b5\u901a\u5e38\u53d1\u751f\u5728\u5185\u5b58\u5bc6\u96c6\u578b\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u4f8b\u5982\u5927\u6570\u636e\u5904\u7406\u3001\u673a\u5668\u5b66\u4e60\u6a21\u578b\u8bad\u7ec3\u7b49\u3002<\/p>\n<h2 id=\"%e9%94%99%e8%af%af%e5%8e%9f%e5%9b%a0%e5%88%86%e6%9e%90-ccWjpPlCOK\">\u9519\u8bef\u539f\u56e0\u5206\u6790<\/h2>\n<ul>\n<li><strong>\u5185\u5b58\u9650\u5236\u8bbe\u7f6e\u4e0d\u5f53\uff1a<\/strong>\u5728\u521b\u5efa\u5bb9\u5668\u65f6\uff0c\u5982\u679c\u672a\u6b63\u786e\u8bbe\u7f6e\u5185\u5b58\u9650\u5236\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5bb9\u5668\u5728\u8fd0\u884c\u65f6\u6d88\u8017\u8fc7\u591a\u5185\u5b58\u3002<\/li>\n<li><strong>\u5e94\u7528\u7a0b\u5e8f\u5185\u5b58\u6cc4\u6f0f\uff1a<\/strong>\u67d0\u4e9b\u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u5b58\u5728\u5185\u5b58\u6cc4\u6f0f\u95ee\u9898\uff0c\u5bfc\u81f4\u5176\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u4e0d\u65ad\u6d88\u8017\u5185\u5b58\uff0c\u6700\u7ec8\u8d85\u51fa\u9650\u5236\u3002<\/li>\n<li><strong>\u8d1f\u8f7d\u8fc7\u9ad8\uff1a<\/strong>\u5728\u9ad8\u8d1f\u8f7d\u60c5\u51b5\u4e0b\uff0c\u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u4f1a\u9700\u8981\u66f4\u591a\u7684\u5185\u5b58\u6765\u5904\u7406\u8bf7\u6c42\uff0c\u4ece\u800c\u5bfc\u81f4\u8d85\u51fa\u9650\u5236\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3memory-limit-exceeded%e9%94%99%e8%af%af-ccWjpPlCOK\">\u5982\u4f55\u89e3\u51b3\u201cmemory limit exceeded\u201d\u9519\u8bef<\/h2>\n<h3 id=\"1-%e8%b0%83%e6%95%b4%e5%86%85%e5%ad%98%e9%99%90%e5%88%b6-ccWjpPlCOK\">1. \u8c03\u6574\u5185\u5b58\u9650\u5236<\/h3>\n<p>\u6700\u76f4\u63a5\u7684\u89e3\u51b3\u529e\u6cd5\u662f\u589e\u52a0\u5bb9\u5668\u7684\u5185\u5b58\u9650\u5236\u3002\u5728\u521b\u5efa\u6216\u8fd0\u884c\u5bb9\u5668\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u8bbe\u7f6e\u5185\u5b58\u9650\u5236\uff1a<\/p>\n<pre><code>docker run -m 512m my_container<\/code><\/pre>\n<p>\u4e0a\u8ff0\u547d\u4ee4\u5c06\u5bb9\u5668\u7684\u5185\u5b58\u9650\u5236\u8bbe\u7f6e\u4e3a512MB\u3002\u6839\u636e\u5e94\u7528\u7a0b\u5e8f\u7684\u9700\u6c42\uff0c\u60a8\u53ef\u4ee5\u9002\u5f53\u8c03\u6574\u8fd9\u4e2a\u503c\u3002<\/p>\n<h3 id=\"2-%e4%bc%98%e5%8c%96%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f-ccWjpPlCOK\">2. \u4f18\u5316\u5e94\u7528\u7a0b\u5e8f<\/h3>\n<p>\u5982\u679c\u5e94\u7528\u7a0b\u5e8f\u5b58\u5728\u5185\u5b58\u6cc4\u6f0f\u6216\u4e0d\u5fc5\u8981\u7684\u5185\u5b58\u6d88\u8017\uff0c\u4f18\u5316\u4ee3\u7801\u662f\u89e3\u51b3\u95ee\u9898\u7684\u5173\u952e\u3002\u53ef\u4ee5\u4f7f\u7528\u5185\u5b58\u5206\u6790\u5de5\u5177\uff08\u5982Valgrind\u3001Heaptrack\u7b49\uff09\u6765\u68c0\u6d4b\u548c\u4fee\u590d\u5185\u5b58\u6cc4\u6f0f\u3002<\/p>\n<h3 id=\"3-%e7%9b%91%e6%8e%a7%e5%92%8c%e5%88%86%e6%9e%90%e5%86%85%e5%ad%98%e4%bd%bf%e7%94%a8%e6%83%85%e5%86%b5-ccWjpPlCOK\">3. \u76d1\u63a7\u548c\u5206\u6790\u5185\u5b58\u4f7f\u7528\u60c5\u51b5<\/h3>\n<p>\u4f7f\u7528Docker\u7684\u76d1\u63a7\u5de5\u5177\uff08\u5982Docker Stats\uff09\u6765\u5b9e\u65f6\u76d1\u63a7\u5bb9\u5668\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u53ca\u65f6\u53d1\u73b0\u95ee\u9898\u5e76\u8fdb\u884c\u8c03\u6574\u3002<\/p>\n<pre><code>docker stats my_container<\/code><\/pre>\n<p>\u8be5\u547d\u4ee4\u5c06\u663e\u793a\u6307\u5b9a\u5bb9\u5668\u7684\u5b9e\u65f6\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\uff0c\u5305\u62ec\u5185\u5b58\u4f7f\u7528\u91cf\u3002<\/p>\n<h3 id=\"4-%e4%bd%bf%e7%94%a8swarm%e6%88%96kubernetes%e8%bf%9b%e8%a1%8c%e8%b4%9f%e8%bd%bd%e5%9d%87%e8%a1%a1-ccWjpPlCOK\">4. \u4f7f\u7528Swarm\u6216Kubernetes\u8fdb\u884c\u8d1f\u8f7d\u5747\u8861<\/h3>\n<p>\u5982\u679c\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u5904\u7406\u5927\u91cf\u8bf7\u6c42\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528Docker Swarm\u6216Kubernetes\u8fdb\u884c\u8d1f\u8f7d\u5747\u8861\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5c06\u8d1f\u8f7d\u5206\u6563\u5230\u591a\u4e2a\u5bb9\u5668\u4e0a\uff0c\u4ece\u800c\u51cf\u5c11\u5355\u4e2a\u5bb9\u5668\u7684\u5185\u5b58\u538b\u529b\u3002<\/p>\n<h2 id=\"%e6%80%bb%e7%bb%93-ccWjpPlCOK\">\u603b\u7ed3<\/h2>\n<p>\u5728Docker\u5bb9\u5668\u4e2d\u9047\u5230\u201cmemory limit exceeded\u201d\u9519\u8bef\u65f6\uff0c\u9996\u5148\u8981\u5206\u6790\u539f\u56e0\uff0c\u7136\u540e\u91c7\u53d6\u76f8\u5e94\u7684\u89e3\u51b3\u63aa\u65bd\u3002\u901a\u8fc7\u8c03\u6574\u5185\u5b58\u9650\u5236\u3001\u4f18\u5316\u5e94\u7528\u7a0b\u5e8f\u3001\u76d1\u63a7\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u4ee5\u53ca\u4f7f\u7528\u8d1f\u8f7d\u5747\u8861\u5de5\u5177\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\u3002\u5bf9\u4e8e\u9700\u8981\u9ad8\u6027\u80fd\u548c\u9ad8\u53ef\u7528\u6027\u7684\u5e94\u7528\uff0c\u9009\u62e9\u5408\u9002\u7684\u670d\u52a1\u5668\u548c\u4e91\u670d\u52a1\u81f3\u5173\u91cd\u8981\u3002\u7c73\u4e91\u63d0\u4f9b\u591a\u79cd<em><a href=\"https:\/\/fwq.ai\">\u7f8e\u56fdVPS<\/a><\/em>\u548c<em><a href=\"https:\/\/fwq.ai\">\u4e91\u670d\u52a1\u5668<\/a><\/em>\u89e3\u51b3\u65b9\u6848\uff0c\u5e2e\u52a9\u60a8\u6784\u5efa\u7a33\u5b9a\u9ad8\u6548\u7684\u5e94\u7528\u73af\u5883\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker\u6545\u969c\u7801\u548c\u89e3\u51b3\u529e\u6cd5 &#8211; Error: memory limit exceeded \u5728\u4f7f\u7528Docker\u5bb9\u5668\u65f6\uff0c\u5f00\u53d1\u8005\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u9519\u8bef\u7801\uff0c\u5176\u4e2d\u201cmemory limit exceeded\u201d\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u95ee\u9898\u3002\u8fd9\u4e00\u9519\u8bef\u901a\u5e38\u8868\u793a\u5bb9\u5668\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u8d85\u51fa\u4e86\u5206\u914d\u7ed9\u5b83\u7684\u5185\u5b58\u9650\u5236\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u8fd9\u4e00\u9519\u8bef\u7684\u539f\u56e0\u3001\u5f71\u54cd\u4ee5\u53ca\u89e3\u51b3\u529e\u6cd5\u3002 \u4ec0\u4e48\u662f\u201cmemory limit exceeded\u201d\u9519\u8bef\uff1f \u5f53Docker\u5bb9\u5668\u88ab\u5206\u914d\u4e86\u7279\u5b9a\u7684\u5185\u5b58\u9650\u5236\u65f6\uff0c\u5982\u679c\u5bb9\u5668\u5185\u7684\u5e94\u7528\u7a0b\u5e8f\u5c1d\u8bd5\u4f7f\u7528\u8d85\u8fc7\u8be5\u9650\u5236\u7684\u5185\u5b58\uff0c\u5c31\u4f1a\u89e6\u53d1\u201cmemory limit exceeded\u201d\u9519\u8bef\u3002\u8fd9\u79cd\u60c5\u51b5\u901a\u5e38\u53d1\u751f\u5728\u5185\u5b58\u5bc6\u96c6\u578b\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u4f8b\u5982\u5927\u6570\u636e\u5904\u7406\u3001\u673a\u5668\u5b66\u4e60\u6a21\u578b\u8bad\u7ec3\u7b49\u3002 \u9519\u8bef\u539f\u56e0\u5206\u6790 \u5185\u5b58\u9650\u5236\u8bbe\u7f6e\u4e0d\u5f53\uff1a\u5728\u521b\u5efa\u5bb9\u5668\u65f6\uff0c\u5982\u679c\u672a\u6b63\u786e\u8bbe\u7f6e\u5185\u5b58\u9650\u5236\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5bb9\u5668\u5728\u8fd0\u884c\u65f6\u6d88\u8017\u8fc7\u591a\u5185\u5b58\u3002 \u5e94\u7528\u7a0b\u5e8f\u5185\u5b58\u6cc4\u6f0f\uff1a\u67d0\u4e9b\u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u5b58\u5728\u5185\u5b58\u6cc4\u6f0f\u95ee\u9898\uff0c\u5bfc\u81f4\u5176\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u4e0d\u65ad\u6d88\u8017\u5185\u5b58\uff0c\u6700\u7ec8\u8d85\u51fa\u9650\u5236\u3002 \u8d1f\u8f7d\u8fc7\u9ad8\uff1a\u5728\u9ad8\u8d1f\u8f7d\u60c5\u51b5\u4e0b\uff0c\u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u4f1a\u9700\u8981\u66f4\u591a\u7684\u5185\u5b58\u6765\u5904\u7406\u8bf7\u6c42\uff0c\u4ece\u800c\u5bfc\u81f4\u8d85\u51fa\u9650\u5236\u3002 \u5982\u4f55\u89e3\u51b3\u201cmemory limit exceeded\u201d\u9519\u8bef 1. \u8c03\u6574\u5185\u5b58\u9650\u5236 \u6700\u76f4\u63a5\u7684\u89e3\u51b3\u529e\u6cd5\u662f\u589e\u52a0\u5bb9\u5668\u7684\u5185\u5b58\u9650\u5236\u3002\u5728\u521b\u5efa\u6216\u8fd0\u884c\u5bb9\u5668\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u8bbe\u7f6e\u5185\u5b58\u9650\u5236\uff1a docker run -m 512m my_container \u4e0a\u8ff0\u547d\u4ee4\u5c06\u5bb9\u5668\u7684\u5185\u5b58\u9650\u5236\u8bbe\u7f6e\u4e3a512MB\u3002\u6839\u636e\u5e94\u7528\u7a0b\u5e8f\u7684\u9700\u6c42\uff0c\u60a8\u53ef\u4ee5\u9002\u5f53\u8c03\u6574\u8fd9\u4e2a\u503c\u3002 2. \u4f18\u5316\u5e94\u7528\u7a0b\u5e8f \u5982\u679c\u5e94\u7528\u7a0b\u5e8f\u5b58\u5728\u5185\u5b58\u6cc4\u6f0f\u6216\u4e0d\u5fc5\u8981\u7684\u5185\u5b58\u6d88\u8017\uff0c\u4f18\u5316\u4ee3\u7801\u662f\u89e3\u51b3\u95ee\u9898\u7684\u5173\u952e\u3002\u53ef\u4ee5\u4f7f\u7528\u5185\u5b58\u5206\u6790\u5de5\u5177\uff08\u5982Valgrind\u3001Heaptrack\u7b49\uff09\u6765\u68c0\u6d4b\u548c\u4fee\u590d\u5185\u5b58\u6cc4\u6f0f\u3002 3. \u76d1\u63a7\u548c\u5206\u6790\u5185\u5b58\u4f7f\u7528\u60c5\u51b5 \u4f7f\u7528Docker\u7684\u76d1\u63a7\u5de5\u5177\uff08\u5982Docker Stats\uff09\u6765\u5b9e\u65f6\u76d1\u63a7\u5bb9\u5668\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u53ca\u65f6\u53d1\u73b0\u95ee\u9898\u5e76\u8fdb\u884c\u8c03\u6574\u3002 docker stats my_container \u8be5\u547d\u4ee4\u5c06\u663e\u793a\u6307\u5b9a\u5bb9\u5668\u7684\u5b9e\u65f6\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\uff0c\u5305\u62ec\u5185\u5b58\u4f7f\u7528\u91cf\u3002 4. \u4f7f\u7528Swarm\u6216Kubernetes\u8fdb\u884c\u8d1f\u8f7d\u5747\u8861 \u5982\u679c\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u5904\u7406\u5927\u91cf\u8bf7\u6c42\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528Docker Swarm\u6216Kubernetes\u8fdb\u884c\u8d1f\u8f7d\u5747\u8861\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5c06\u8d1f\u8f7d\u5206\u6563\u5230\u591a\u4e2a\u5bb9\u5668\u4e0a\uff0c\u4ece\u800c\u51cf\u5c11\u5355\u4e2a\u5bb9\u5668\u7684\u5185\u5b58\u538b\u529b\u3002 \u603b\u7ed3 \u5728Docker\u5bb9\u5668\u4e2d\u9047\u5230\u201cmemory limit exceeded\u201d\u9519\u8bef\u65f6\uff0c\u9996\u5148\u8981\u5206\u6790\u539f\u56e0\uff0c\u7136\u540e\u91c7\u53d6\u76f8\u5e94\u7684\u89e3\u51b3\u63aa\u65bd\u3002\u901a\u8fc7\u8c03\u6574\u5185\u5b58\u9650\u5236\u3001\u4f18\u5316\u5e94\u7528\u7a0b\u5e8f\u3001\u76d1\u63a7\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u4ee5\u53ca\u4f7f\u7528\u8d1f\u8f7d\u5747\u8861\u5de5\u5177\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\u3002\u5bf9\u4e8e\u9700\u8981\u9ad8\u6027\u80fd\u548c\u9ad8\u53ef\u7528\u6027\u7684\u5e94\u7528\uff0c\u9009\u62e9\u5408\u9002\u7684\u670d\u52a1\u5668\u548c\u4e91\u670d\u52a1\u81f3\u5173\u91cd\u8981\u3002\u7c73\u4e91\u63d0\u4f9b\u591a\u79cd\u7f8e\u56fdVPS\u548c\u4e91\u670d\u52a1\u5668\u89e3\u51b3\u65b9\u6848\uff0c\u5e2e\u52a9\u60a8\u6784\u5efa\u7a33\u5b9a\u9ad8\u6548\u7684\u5e94\u7528\u73af\u5883\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-13628","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/13628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=13628"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/13628\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=13628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=13628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=13628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}