{"id":7738,"date":"2024-11-14T12:48:26","date_gmt":"2024-11-14T04:48:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7738\/"},"modified":"2024-11-14T12:48:26","modified_gmt":"2024-11-14T04:48:26","slug":"docker-compose-%e9%83%a8%e7%bd%b2-mysql-%e9%81%87%e5%88%b0%e9%94%99%e8%af%af%e5%a6%82%e4%bd%95%e6%8e%92%e6%9f%a5%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7738\/","title":{"rendered":"Docker-Compose \u90e8\u7f72 MySQL \u9047\u5230\u9519\u8bef\u5982\u4f55\u6392\u67e5\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173121160618561.jpg\" class=\"aligncenter\" title=\"Docker-Compose \u90e8\u7f72 MySQL \u9047\u5230\u9519\u8bef\u5982\u4f55\u6392\u67e5\uff1f\u63d2\u56fe\" alt=\"Docker-Compose \u90e8\u7f72 MySQL \u9047\u5230\u9519\u8bef\u5982\u4f55\u6392\u67e5\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>-compose \u90e8\u7f72  \u9047\u5230\u9519\u8bef<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 docker-compose \u90e8\u7f72 mysql \u65f6\uff0c\u5982\u679c\u9047\u5230\u9519\u8bef\uff0c\u53ef\u4ee5\u4ece\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\u6392\u67e5\uff1a<\/p>\n<p><strong>1. \u67e5\u770b docker-compose.yml \u6587\u4ef6<\/strong><\/p>\n<p>\u786e\u8ba4 docker-compose.yml \u6587\u4ef6\u7684\u8bed\u6cd5\u6b63\u786e\uff0c\u6240\u9700\u5b57\u6bb5\u586b\u5199\u5b8c\u6574\u3002\u5176\u4e2d\uff0c\u9700\u8981\u91cd\u70b9\u5173\u6ce8\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<ul>\n<li> <strong>image:<\/strong> \u6307\u5b9a\u4f7f\u7528\u7684 mysql \u955c\u50cf\uff0c\u786e\u4fdd\u7248\u672c\u6b63\u786e\u3002<\/li>\n<li> <strong>volumes:<\/strong> \u6302\u8f7d\u5bbf\u4e3b\u673a\u76ee\u5f55\u5230\u5bb9\u5668\u5185\uff0c\u68c0\u67e5\u6302\u8f7d\u8def\u5f84\u662f\u5426\u5b58\u5728\u4e14\u5177\u6709\u8bfb\u5199\u6743\u9650\u3002<\/li>\n<li> <strong>environment:<\/strong> \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u5982 mysql_root_password\u3002<\/li>\n<li> <strong>command:<\/strong> \u6307\u5b9a\u5bb9\u5668\u542f\u52a8\u65f6\u6267\u884c\u7684\u547d\u4ee4\uff0c\u786e\u8ba4\u53c2\u6570\u6b63\u786e\u3002<\/li>\n<\/ul>\n<p><strong>2. \u786e\u8ba4\u5bbf\u4e3b\u673a\u6302\u8f7d\u76ee\u5f55\u5b58\u5728\u5e76\u53ef\u5199<\/strong><\/p>\n<p>\u5f53\u4f7f\u7528 volumes \u6302\u8f7d\u5bbf\u4e3b\u673a\u76ee\u5f55\u65f6\uff0c\u9700\u8981\u786e\u4fdd\u6302\u8f7d\u76ee\u5f55\u5b58\u5728\u4e14\u5bb9\u5668\u7528\u6237\u5177\u6709\u5199\u5165\u6743\u9650\u3002\u5982\u679c\u9700\u8981\u6302\u8f7d\u5b50\u76ee\u5f55\uff0c\u5219\u9700\u8981\u5148\u5728\u5bbf\u4e3b\u673a\u521b\u5efa\u8be5\u5b50\u76ee\u5f55\u3002<\/p>\n<p><strong>3. \u68c0\u67e5 \/etc\/mysql\/conf.d \u76ee\u5f55<\/strong><\/p>\n<p>\u5728 docker-compose.yml \u6587\u4ef6\u4e2d\uff0c\u60a8\u6302\u8f7d\u4e86 \/data\/docker\/mysql\/etc \u76ee\u5f55\u5230\u5bb9\u5668\u5185\u7684 \/etc\/mysql \u76ee\u5f55\uff0c\u4f46\u6ca1\u6709\u6302\u8f7d conf.d \u5b50\u76ee\u5f55\u3002\u5982\u679c\u60a8\u7684 mysql \u914d\u7f6e\u6587\u4ef6\u4e2d\u5305\u542b\u4e86\u5728 conf.d \u76ee\u5f55\u4e0b\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5219\u9700\u8981\u5728 docker-compose.yml \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre>- \/data\/docker\/mysql\/etc\/conf.d:\/etc\/mysql\/conf.d:ro<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fDocker-Compose \u90e8\u7f72 MySQL \u9047\u5230\u9519\u8bef\u5982\u4f55\u6392\u67e5\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>-compose \u90e8\u7f72 \u9047\u5230\u9519\u8bef \u5728\u4f7f\u7528 docker-compose \u90e8\u7f72 mysql \u65f6\uff0c\u5982\u679c\u9047\u5230\u9519\u8bef\uff0c\u53ef\u4ee5\u4ece\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\u6392\u67e5\uff1a 1. \u67e5\u770b docker-compose.yml \u6587\u4ef6 \u786e\u8ba4 docker-compose.yml \u6587\u4ef6\u7684\u8bed\u6cd5\u6b63\u786e\uff0c\u6240\u9700\u5b57\u6bb5\u586b\u5199\u5b8c\u6574\u3002\u5176\u4e2d\uff0c\u9700\u8981\u91cd\u70b9\u5173\u6ce8\u4ee5\u4e0b\u5185\u5bb9\uff1a image: \u6307\u5b9a\u4f7f\u7528\u7684 mysql \u955c\u50cf\uff0c\u786e\u4fdd\u7248\u672c\u6b63\u786e\u3002 volumes: \u6302\u8f7d\u5bbf\u4e3b\u673a\u76ee\u5f55\u5230\u5bb9\u5668\u5185\uff0c\u68c0\u67e5\u6302\u8f7d\u8def\u5f84\u662f\u5426\u5b58\u5728\u4e14\u5177\u6709\u8bfb\u5199\u6743\u9650\u3002 environment: \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u5982 mysql_root_password\u3002 command: \u6307\u5b9a\u5bb9\u5668\u542f\u52a8\u65f6\u6267\u884c\u7684\u547d\u4ee4\uff0c\u786e\u8ba4\u53c2\u6570\u6b63\u786e\u3002 2. \u786e\u8ba4\u5bbf\u4e3b\u673a\u6302\u8f7d\u76ee\u5f55\u5b58\u5728\u5e76\u53ef\u5199 \u5f53\u4f7f\u7528 volumes \u6302\u8f7d\u5bbf\u4e3b\u673a\u76ee\u5f55\u65f6\uff0c\u9700\u8981\u786e\u4fdd\u6302\u8f7d\u76ee\u5f55\u5b58\u5728\u4e14\u5bb9\u5668\u7528\u6237\u5177\u6709\u5199\u5165\u6743\u9650\u3002\u5982\u679c\u9700\u8981\u6302\u8f7d\u5b50\u76ee\u5f55\uff0c\u5219\u9700\u8981\u5148\u5728\u5bbf\u4e3b\u673a\u521b\u5efa\u8be5\u5b50\u76ee\u5f55\u3002 3. \u68c0\u67e5 \/etc\/mysql\/conf.d \u76ee\u5f55 \u5728 docker-compose.yml \u6587\u4ef6\u4e2d\uff0c\u60a8\u6302\u8f7d\u4e86 \/data\/docker\/mysql\/etc \u76ee\u5f55\u5230\u5bb9\u5668\u5185\u7684 \/etc\/mysql \u76ee\u5f55\uff0c\u4f46\u6ca1\u6709\u6302\u8f7d conf.d \u5b50\u76ee\u5f55\u3002\u5982\u679c\u60a8\u7684 mysql \u914d\u7f6e\u6587\u4ef6\u4e2d\u5305\u542b\u4e86\u5728 conf.d \u76ee\u5f55\u4e0b\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5219\u9700\u8981\u5728 docker-compose.yml \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a &#8211; \/data\/docker\/mysql\/etc\/conf.d:\/etc\/mysql\/conf.d:ro \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u5c31\u662fDocker-Compose \u90e8\u7f72 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7738","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7738","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=7738"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7738\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}