{"id":13627,"date":"2024-11-15T20:03:56","date_gmt":"2024-11-15T12:03:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/13627\/"},"modified":"2024-11-15T20:03:56","modified_gmt":"2024-11-15T12:03:56","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-response-from-daemon-cannot-allocate-memory","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/13627\/","title":{"rendered":"Docker\u6545\u969c\u7801\u548c\u89e3\u51b3\u529e\u6cd5 &#8211; Error response from daemon: cannot allocate memory"},"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-response-from-daemon-cannot-allocate-memory-YkEjqBPzRP\">Docker\u6545\u969c\u7801\u548c\u89e3\u51b3\u529e\u6cd5 &#8211; Error response from daemon: cannot allocate memory<\/h1>\n<p>\u5728\u4f7f\u7528Docker\u8fdb\u884c\u5bb9\u5668\u5316\u90e8\u7f72\u65f6\uff0c\u7528\u6237\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u79cd\u9519\u8bef\u7801\uff0c\u5176\u4e2d\u4e4b\u4e00\u5c31\u662f\u201cError response from daemon: cannot allocate memory\u201d\u3002\u8fd9\u4e2a\u9519\u8bef\u901a\u5e38\u8868\u793aDocker\u5b88\u62a4\u8fdb\u7a0b\u65e0\u6cd5\u5206\u914d\u8db3\u591f\u7684\u5185\u5b58\u6765\u542f\u52a8\u6216\u8fd0\u884c\u5bb9\u5668\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u8be5\u9519\u8bef\u7684\u539f\u56e0\u53ca\u5176\u89e3\u51b3\u529e\u6cd5\u3002<\/p>\n<h2 id=\"%e9%94%99%e8%af%af%e5%8e%9f%e5%9b%a0%e5%88%86%e6%9e%90-YkEjqBPzRP\">\u9519\u8bef\u539f\u56e0\u5206\u6790<\/h2>\n<p>\u5f53Docker\u5bb9\u5668\u542f\u52a8\u65f6\uff0c\u5b83\u9700\u8981\u4e00\u5b9a\u91cf\u7684\u5185\u5b58\u6765\u8fd0\u884c\u3002\u5982\u679c\u7cfb\u7edf\u7684\u53ef\u7528\u5185\u5b58\u4e0d\u8db3\uff0cDocker\u5c31\u4f1a\u8fd4\u56de\u201ccannot allocate memory\u201d\u7684\u9519\u8bef\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u53ef\u80fd\u5bfc\u81f4\u6b64\u9519\u8bef\u7684\u539f\u56e0\uff1a<\/p>\n<ul>\n<li><strong>\u7cfb\u7edf\u5185\u5b58\u4e0d\u8db3\uff1a<\/strong>\u5982\u679c\u4e3b\u673a\u7684\u7269\u7406\u5185\u5b58\u4e0d\u8db3\u4ee5\u6ee1\u8db3\u5bb9\u5668\u7684\u9700\u6c42\uff0cDocker\u5c06\u65e0\u6cd5\u5206\u914d\u5185\u5b58\u3002<\/li>\n<li><strong>\u5185\u5b58\u9650\u5236\u8bbe\u7f6e\uff1a<\/strong>Docker\u5bb9\u5668\u53ef\u4ee5\u8bbe\u7f6e\u5185\u5b58\u9650\u5236\uff0c\u5982\u679c\u8bbe\u7f6e\u7684\u9650\u5236\u4f4e\u4e8e\u5bb9\u5668\u6240\u9700\u7684\u5185\u5b58\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6b64\u9519\u8bef\u3002<\/li>\n<li><strong>\u5176\u4ed6\u8fdb\u7a0b\u5360\u7528\u5185\u5b58\uff1a<\/strong>\u4e3b\u673a\u4e0a\u8fd0\u884c\u7684\u5176\u4ed6\u8fdb\u7a0b\u53ef\u80fd\u5360\u7528\u4e86\u5927\u91cf\u5185\u5b58\uff0c\u5bfc\u81f4Docker\u65e0\u6cd5\u5206\u914d\u6240\u9700\u7684\u5185\u5b58\u3002<\/li>\n<\/ul>\n<h2 id=\"%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95-YkEjqBPzRP\">\u89e3\u51b3\u529e\u6cd5<\/h2>\n<p>\u9488\u5bf9\u201ccannot allocate memory\u201d\u9519\u8bef\uff0c\u7528\u6237\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u51e0\u79cd\u89e3\u51b3\u529e\u6cd5\uff1a<\/p>\n<h3 id=\"1-%e6%a3%80%e6%9f%a5%e7%b3%bb%e7%bb%9f%e5%86%85%e5%ad%98%e4%bd%bf%e7%94%a8%e6%83%85%e5%86%b5-YkEjqBPzRP\">1. \u68c0\u67e5\u7cfb\u7edf\u5185\u5b58\u4f7f\u7528\u60c5\u51b5<\/h3>\n<p>\u9996\u5148\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5\u7cfb\u7edf\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff1a<\/p>\n<pre><code>free -m<\/code><\/pre>\n<p>\u8be5\u547d\u4ee4\u5c06\u663e\u793a\u7cfb\u7edf\u7684\u603b\u5185\u5b58\u3001\u5df2\u7528\u5185\u5b58\u548c\u53ef\u7528\u5185\u5b58\u3002\u5982\u679c\u53ef\u7528\u5185\u5b58\u975e\u5e38\u5c11\uff0c\u8003\u8651\u5173\u95ed\u4e00\u4e9b\u4e0d\u5fc5\u8981\u7684\u8fdb\u7a0b\u4ee5\u91ca\u653e\u5185\u5b58\u3002<\/p>\n<h3 id=\"2-%e5%a2%9e%e5%8a%a0docker%e5%ae%b9%e5%99%a8%e7%9a%84%e5%86%85%e5%ad%98%e9%99%90%e5%88%b6-YkEjqBPzRP\">2. \u589e\u52a0Docker\u5bb9\u5668\u7684\u5185\u5b58\u9650\u5236<\/h3>\n<p>\u5982\u679c\u5bb9\u5668\u7684\u5185\u5b58\u9650\u5236\u8bbe\u7f6e\u8fc7\u4f4e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u589e\u52a0\u5185\u5b58\u9650\u5236\uff1a<\/p>\n<pre><code>docker run -m 512m your_image<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5bb9\u5668\u7684\u5185\u5b58\u9650\u5236\u88ab\u8bbe\u7f6e\u4e3a512MB\u3002\u6839\u636e\u9700\u8981\u8c03\u6574\u8fd9\u4e2a\u503c\u3002<\/p>\n<h3 id=\"3-%e5%a2%9e%e5%8a%a0%e4%b8%bb%e6%9c%ba%e7%9a%84%e7%89%a9%e7%90%86%e5%86%85%e5%ad%98-YkEjqBPzRP\">3. \u589e\u52a0\u4e3b\u673a\u7684\u7269\u7406\u5185\u5b58<\/h3>\n<p>\u5982\u679c\u7cfb\u7edf\u5185\u5b58\u4e0d\u8db3\u4ee5\u652f\u6301\u6240\u6709\u8fd0\u884c\u7684\u5bb9\u5668\u548c\u8fdb\u7a0b\uff0c\u8003\u8651\u589e\u52a0\u4e3b\u673a\u7684\u7269\u7406\u5185\u5b58\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u66f4\u591a\u7684RAM\u6761\u6765\u5b9e\u73b0\u3002<\/p>\n<h3 id=\"4-%e4%bd%bf%e7%94%a8swap%e7%a9%ba%e9%97%b4-YkEjqBPzRP\">4. \u4f7f\u7528Swap\u7a7a\u95f4<\/h3>\n<p>\u5982\u679c\u7269\u7406\u5185\u5b58\u4e0d\u8db3\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528Swap\u7a7a\u95f4\u3002Swap\u7a7a\u95f4\u662f\u786c\u76d8\u4e0a\u7684\u4e00\u90e8\u5206\uff0c\u7528\u4e8e\u4e34\u65f6\u5b58\u50a8\u4e0d\u6d3b\u8dc3\u7684\u5185\u5b58\u6570\u636e\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efaSwap\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo fallocate -l 1G \/swapfile\nsudo chmod 600 \/swapfile\nsudo mkswap \/swapfile\nsudo swapon \/swapfile<\/code><\/pre>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a1GB\u7684Swap\u6587\u4ef6\u3002\u8bf7\u6ce8\u610f\uff0c\u4f7f\u7528Swap\u7a7a\u95f4\u4f1a\u964d\u4f4e\u6027\u80fd\uff0c\u56e0\u6b64\u5e94\u8c28\u614e\u4f7f\u7528\u3002<\/p>\n<h2 id=\"%e6%80%bb%e7%bb%93-YkEjqBPzRP\">\u603b\u7ed3<\/h2>\n<p>\u5728Docker\u4f7f\u7528\u8fc7\u7a0b\u4e2d\uff0c\u9047\u5230\u201cError response from daemon: cannot allocate memory\u201d\u9519\u8bef\u662f\u6bd4\u8f83\u5e38\u89c1\u7684\u3002\u901a\u8fc7\u68c0\u67e5\u7cfb\u7edf\u5185\u5b58\u3001\u8c03\u6574\u5bb9\u5668\u5185\u5b58\u9650\u5236\u3001\u589e\u52a0\u7269\u7406\u5185\u5b58\u6216\u4f7f\u7528Swap\u7a7a\u95f4\u7b49\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u89e3\u51b3\u8be5\u95ee\u9898\u3002\u5bf9\u4e8e\u9700\u8981\u9ad8\u6027\u80fd\u548c\u7a33\u5b9a\u6027\u7684\u7528\u6237\uff0c\u9009\u62e9\u5408\u9002\u7684<a href=\"https:\/\/fwq.ai\">\u4e91\u670d\u52a1\u5668<\/a>\u6216<a href=\"https:\/\/fwq.ai\">VPS<\/a>\u89e3\u51b3\u65b9\u6848\u5c06\u662f\u4e00\u4e2a\u660e\u667a\u7684\u9009\u62e9\u3002\u7c73\u4e91\u63d0\u4f9b\u591a\u79cd\u670d\u52a1\u5668\u9009\u9879\uff0c\u6ee1\u8db3\u4e0d\u540c\u7528\u6237\u7684\u9700\u6c42\uff0c\u786e\u4fdd\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u987a\u5229\u8fd0\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker\u6545\u969c\u7801\u548c\u89e3\u51b3\u529e\u6cd5 &#8211; Error response from daemon: cannot allocate memory \u5728\u4f7f\u7528Docker\u8fdb\u884c\u5bb9\u5668\u5316\u90e8\u7f72\u65f6\uff0c\u7528\u6237\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u79cd\u9519\u8bef\u7801\uff0c\u5176\u4e2d\u4e4b\u4e00\u5c31\u662f\u201cError response from daemon: cannot allocate memory\u201d\u3002\u8fd9\u4e2a\u9519\u8bef\u901a\u5e38\u8868\u793aDocker\u5b88\u62a4\u8fdb\u7a0b\u65e0\u6cd5\u5206\u914d\u8db3\u591f\u7684\u5185\u5b58\u6765\u542f\u52a8\u6216\u8fd0\u884c\u5bb9\u5668\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u8be5\u9519\u8bef\u7684\u539f\u56e0\u53ca\u5176\u89e3\u51b3\u529e\u6cd5\u3002 \u9519\u8bef\u539f\u56e0\u5206\u6790 \u5f53Docker\u5bb9\u5668\u542f\u52a8\u65f6\uff0c\u5b83\u9700\u8981\u4e00\u5b9a\u91cf\u7684\u5185\u5b58\u6765\u8fd0\u884c\u3002\u5982\u679c\u7cfb\u7edf\u7684\u53ef\u7528\u5185\u5b58\u4e0d\u8db3\uff0cDocker\u5c31\u4f1a\u8fd4\u56de\u201ccannot allocate memory\u201d\u7684\u9519\u8bef\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u53ef\u80fd\u5bfc\u81f4\u6b64\u9519\u8bef\u7684\u539f\u56e0\uff1a \u7cfb\u7edf\u5185\u5b58\u4e0d\u8db3\uff1a\u5982\u679c\u4e3b\u673a\u7684\u7269\u7406\u5185\u5b58\u4e0d\u8db3\u4ee5\u6ee1\u8db3\u5bb9\u5668\u7684\u9700\u6c42\uff0cDocker\u5c06\u65e0\u6cd5\u5206\u914d\u5185\u5b58\u3002 \u5185\u5b58\u9650\u5236\u8bbe\u7f6e\uff1aDocker\u5bb9\u5668\u53ef\u4ee5\u8bbe\u7f6e\u5185\u5b58\u9650\u5236\uff0c\u5982\u679c\u8bbe\u7f6e\u7684\u9650\u5236\u4f4e\u4e8e\u5bb9\u5668\u6240\u9700\u7684\u5185\u5b58\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6b64\u9519\u8bef\u3002 \u5176\u4ed6\u8fdb\u7a0b\u5360\u7528\u5185\u5b58\uff1a\u4e3b\u673a\u4e0a\u8fd0\u884c\u7684\u5176\u4ed6\u8fdb\u7a0b\u53ef\u80fd\u5360\u7528\u4e86\u5927\u91cf\u5185\u5b58\uff0c\u5bfc\u81f4Docker\u65e0\u6cd5\u5206\u914d\u6240\u9700\u7684\u5185\u5b58\u3002 \u89e3\u51b3\u529e\u6cd5 \u9488\u5bf9\u201ccannot allocate memory\u201d\u9519\u8bef\uff0c\u7528\u6237\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u51e0\u79cd\u89e3\u51b3\u529e\u6cd5\uff1a 1. \u68c0\u67e5\u7cfb\u7edf\u5185\u5b58\u4f7f\u7528\u60c5\u51b5 \u9996\u5148\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5\u7cfb\u7edf\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff1a free -m \u8be5\u547d\u4ee4\u5c06\u663e\u793a\u7cfb\u7edf\u7684\u603b\u5185\u5b58\u3001\u5df2\u7528\u5185\u5b58\u548c\u53ef\u7528\u5185\u5b58\u3002\u5982\u679c\u53ef\u7528\u5185\u5b58\u975e\u5e38\u5c11\uff0c\u8003\u8651\u5173\u95ed\u4e00\u4e9b\u4e0d\u5fc5\u8981\u7684\u8fdb\u7a0b\u4ee5\u91ca\u653e\u5185\u5b58\u3002 2. \u589e\u52a0Docker\u5bb9\u5668\u7684\u5185\u5b58\u9650\u5236 \u5982\u679c\u5bb9\u5668\u7684\u5185\u5b58\u9650\u5236\u8bbe\u7f6e\u8fc7\u4f4e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u589e\u52a0\u5185\u5b58\u9650\u5236\uff1a docker run -m 512m your_image \u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5bb9\u5668\u7684\u5185\u5b58\u9650\u5236\u88ab\u8bbe\u7f6e\u4e3a512MB\u3002\u6839\u636e\u9700\u8981\u8c03\u6574\u8fd9\u4e2a\u503c\u3002 3. \u589e\u52a0\u4e3b\u673a\u7684\u7269\u7406\u5185\u5b58 \u5982\u679c\u7cfb\u7edf\u5185\u5b58\u4e0d\u8db3\u4ee5\u652f\u6301\u6240\u6709\u8fd0\u884c\u7684\u5bb9\u5668\u548c\u8fdb\u7a0b\uff0c\u8003\u8651\u589e\u52a0\u4e3b\u673a\u7684\u7269\u7406\u5185\u5b58\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u66f4\u591a\u7684RAM\u6761\u6765\u5b9e\u73b0\u3002 4. \u4f7f\u7528Swap\u7a7a\u95f4 \u5982\u679c\u7269\u7406\u5185\u5b58\u4e0d\u8db3\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528Swap\u7a7a\u95f4\u3002Swap\u7a7a\u95f4\u662f\u786c\u76d8\u4e0a\u7684\u4e00\u90e8\u5206\uff0c\u7528\u4e8e\u4e34\u65f6\u5b58\u50a8\u4e0d\u6d3b\u8dc3\u7684\u5185\u5b58\u6570\u636e\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efaSwap\u6587\u4ef6\uff1a sudo fallocate -l 1G \/swapfile sudo chmod [&hellip;]<\/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-13627","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/13627","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=13627"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/13627\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=13627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=13627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=13627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}