{"id":7324,"date":"2023-03-28T21:09:48","date_gmt":"2023-03-28T13:09:48","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=7324"},"modified":"2023-03-28T21:20:05","modified_gmt":"2023-03-28T13:20:05","slug":"%e5%a4%9a%e5%ae%b9%e5%99%a8%e5%ba%94%e7%94%a8%e5%ae%9e%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=7324","title":{"rendered":"\u591a\u5bb9\u5668\u5e94\u7528\u5b9e\u4f8b"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>services:\n    app:\n        #getstart:net-mysql\u662f\u6839\u636edocker\u6587\u6863\u4e2d\u7684\u4e00\u4e2a\u4f8b\u5b50\u81ea\u5df1\u91cd\u65b0\u6784\u5efa\u7684\u955c\u50cf\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u955c\u50cf\u603b\u662f\u9700\u8981\u5f88\u591a\u7684\u4f9d\u8d56\uff0c\u6bcf\u6b21\u8fd0\u884c\u90fd\u56e0\u4e3a\u5404\u79cd\u539f\u56e0\u5361\u4f4f\u4e0d\u52a8\uff0c\u6240\u4ee5\u6211\u5728\u4e00\u6b21\u6210\u529f\u8fd0\u884c\u540e\uff0c\u7528docker commit\u63d0\u4ea4\u4e86\u4e00\u4e2a\u65b0\u7248\u672c\u955c\u50cf\u3002\u867d\u7136\u8fd9\u4e2a\u955c\u50cf\u6bd4\u5b98\u65b9\u7684\u5927\u5f88\u591a\uff0c\u4e0d\u8fc7\u4e0d\u4f1a\u51fa\u73b0\u6bcf\u6b21\u90fd\u56e0\u4e3a\u89e3\u51b3\u4f9d\u8d56\u95ee\u9898\u7b49\u51e0\u4e2a\u5c0f\u65f6\u3002\n        image: getstart:net-mysql\n        command: sh -c \"yarn install &amp;amp;&amp;amp; yarn run dev\"\n        ports:\n            - 3000:3000\n        working_dir: \/app\n        volumes:\n            - .\/:\/app\n#\u8fd9\u91cc\u7684\u201c-\u201d\u8868\u793a\u8fd9\u4e2a\u503c\u662f\u4e2a\u6570\u7ec4\uff0c\u4e5f\u5c31\u662f\u8fd9\u91cc\u53ef\u4ee5\u5199\u591a\u884c\uff0c\u6bcf\u884c\u90fd\u4ee5\u201c-\u201d\u5f00\u5934\u3002\n        environment:\n            MYSQL_HOST: mysql\n            MYSQL_USER: root\n            MYSQL_PASSWORD: secret\n            MYSQL_DB: todos\n        depends_on:\n            mysql:\n                condition: service_healthy\n#\u5982\u4e0a\u9762\u89e3\u91ca\u201c-\u201d\u4e00\u6837\uff0c\u8fd9\u91cc\u4e5f\u53ef\u4ee5\u662f\u5b57\u5178\uff08\u952e-\u503c\u5bf9\uff09\uff0cmysql\u5c31\u662f\u201c\u952e\u201d\uff0c\u800c\u201ccondition: service_healthy\u201d\u5c31\u662f\u201c\u503c\u201d\uff0c\u8fd9\u91cc\u4e5f\u53ef\u4ee5\u5199\u6210\u4e0a\u9762\u7684\u6570\u7ec4\u5f62\u5f0f\uff0c\u4e0d\u8fc7\u5c31\u6ca1\u529e\u6cd5\u5199condition\u4e86\u3002\u8fd9\u91cc\u7684\u610f\u601d\u662f\u201c\u8be5\u955c\u50cf\u7684\u542f\u52a8\u4f9d\u8d56\u4e8emysql\u955c\u50cf\u542f\u52a8\u7684\u5065\u5eb7\u68c0\u67e5\u662f\u5426\u6210\u529f\uff0c\u5728\u5176\u6210\u529f\u540e\u542f\u52a8\u8be5\u955c\u50cf\u201d\n    mysql:\n        image: mysql:8.0\n        volumes:\n            - todo-mysql-data:\/var\/lib\/mysql\n        healthcheck:\n#\u8fd9\u91cc\u662f\u5065\u5eb7\u68c0\u67e5\uff0ctest\u5468\u671f\u6267\u884c\u547d\u4ee4\u201cmysqladmin ping -h localhost\u201d\uff0c\u6267\u884c\u6210\u529f\u4e86\uff0chealthcheck\u5c31\u4ee3\u8868\u6210\u529f\u4e86\uff0c\u4e0a\u9762condition\u7684\u6761\u4ef6\u5c31\u8fbe\u6210\u4e86\u3002\n            test: &#91;\"CMD\",\"mysqladmin\",\"ping\",\"-h\",\"localhost\"]\n            interval: 10s\n            timeout: 5s\n            retries: 3\n        environment:\n            MYSQL_ROOT_PASSWORD: secret\n            MYSQL_DATABASE: todos\n\nvolumes:\n    todo-mysql-data:\n      external: true<\/code><\/pre>\n\n\n\n<p>PS1:\u8be5\u683c\u5f0f\u7684\u7f29\u8fdb\u5f88\u91cd\u8981\uff0c\u6211\u8d77\u521d\u4ee5\u4e3avolumes\u662fmysql\u955c\u50cf\u91cc\u9762\u7684\u6210\u5458\uff0c\u7ed3\u679c\u7528\u4e86\u7f29\u8fdb\uff0c\u540e\u6765\u6392\u67e5\u4e86\u5f88\u4e45\u624d\u53d1\u73b0volumes\u662f\u9876\u7ea7\u7f29\u8fdb\u548cservices\u662f\u540c\u4e00\u7ea7\u522b\u3002\u5176\u5b83\u7f29\u8fdb\u4e5f\u662f\u4e00\u6837\uff0c\u5f04\u9519\u4e86docker compose\u5c31\u8bfb\u4e0d\u51fa\u6765\u3002<\/p>\n\n\n\n<p>PS2\uff1a\u8fd8\u6709\u4e00\u4e2a\u5c31\u662fdocker compose\u662f\u6709\u4e24\u4e2a\u7248\u672c\u7684\uff0c\u4e00\u4e2a\u662fdocker-compose\u5de5\u5177\uff0c\u8fd8\u6709\u4e00\u4e2a\u662f&#8221;docker compose&#8221;\u547d\u4ee4\uff0ccompose\u5de5\u5177\u662f\u8981\u5355\u72ec\u5b89\u88c5\u7684\uff0c\u4ed6\u4eec\u7684\u529f\u80fd\u5dee\u4e0d\u591a\uff0c\u4f46\u662f\u4e5f\u6709\u7565\u5fae\u4e0d\u540c\uff08\u7f51\u4e0a\u662f\u8fd9\u4e48\u8bf4\u7684\uff0c\u6211\u6ca1\u7814\u7a76\u6709\u4ec0\u4e48\u4e0d\u540c\uff0c\u4e5f\u6ca1\u53bb\u5b89\u88c5\uff09\uff0c\u800cdocker compose\u547d\u4ee4\u662fdocker\u7684\u5b50\u547d\u4ee4\u3002\u5728\u542f\u52a8compose\u6587\u4ef6\u65f6\uff0c\u8981\u4f7f\u7528docker compose -f xxxx.yml up -d\u3002\u76f8\u5e94\u7684\u8fd8\u6709docker compose -f xxxx.yml down\u3001docker compose -f xxxx.yml logs\u3001docker compose -f xxxx.yml ps\u7b49\u7b49\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PS1:\u8be5\u683c\u5f0f\u7684\u7f29\u8fdb\u5f88\u91cd\u8981\uff0c\u6211\u8d77\u521d\u4ee5\u4e3avolumes\u662fmysql\u955c\u50cf\u91cc\u9762\u7684\u6210\u5458\uff0c\u7ed3\u679c\u7528\u4e86\u7f29\u8fdb\uff0c\u540e\u6765\u6392\u67e5\u4e86\u5f88\u4e45\u624d\u53d1\u73b0volumes\u662f\u9876\u7ea7\u7f29\u8fdb\u548cservices\u662f\u540c&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=7324\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,37,22],"tags":[],"class_list":["post-7324","post","type-post","status-publish","format-standard","hentry","category-it","category-mysql","category-22"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/7324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7324"}],"version-history":[{"count":4,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/7324\/revisions"}],"predecessor-version":[{"id":7335,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/7324\/revisions\/7335"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}