{"id":49,"date":"2026-05-09T22:26:11","date_gmt":"2026-05-09T14:26:11","guid":{"rendered":"https:\/\/hi.tionmon.de\/?p=49"},"modified":"2026-05-10T00:17:32","modified_gmt":"2026-05-09T16:17:32","slug":"docker-compose-%e8%ae%b2%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/hi.tionmon.de\/?p=49","title":{"rendered":"Docker-Compose \u8bb2\u89e3"},"content":{"rendered":"<div>\n<h1>Docker-Compose \u8bb2\u89e3<\/h1>\n<p>Docker-Compose \u9879\u76ee\u662f Docker \u5b98\u65b9\u7684\u5f00\u6e90\u9879\u76ee\uff0c\u8d1f\u8d23\u5b9e\u73b0\u5bf9 Docker \u5bb9\u5668\u96c6\u7fa4\u7684\u5feb\u901f\u7f16\u6392\u3002Docker-Compose \u9879\u76ee\u7531 Python \u7f16\u5199\uff0c\u8c03\u7528 Docker \u670d\u52a1\u63d0\u4f9b\u7684 API \u6765\u5bf9\u5bb9\u5668\u8fdb\u884c\u7ba1\u7406\u3002\u56e0\u6b64\uff0c\u53ea\u8981\u6240\u64cd\u4f5c\u7684\u5e73\u53f0\u652f\u6301 Docker API\uff0c\u5c31\u53ef\u4ee5\u5728\u5176\u4e0a\u5229\u7528 Compose \u6765\u8fdb\u884c\u7f16\u6392\u7ba1\u7406\u3002<\/p>\n<p>\u901a\u8fc7 Docker-Compose\uff0c\u4e0d\u9700\u8981\u4f7f\u7528 shell \u811a\u672c\u6765\u542f\u52a8\u5bb9\u5668\uff0c\u800c\u662f\u4f7f\u7528 YAML \u6587\u4ef6\u6765\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u7684\u6240\u6709\u670d\u52a1\uff0c\u7136\u540e\u4f7f\u7528\u4e00\u4e2a\u547d\u4ee4\uff0c\u6839\u636e YAML \u7684\u6587\u4ef6\u914d\u7f6e\u521b\u5efa\u5e76\u542f\u52a8\u6240\u6709\u670d\u52a1\u3002<\/p>\n<h2>\u4e00\u3001Docker-Compose \u6a21\u677f\u6587\u4ef6\u7b80\u4ecb\u4e0e\u90e8\u7f72\u67b6\u6784<\/h2>\n<p>Compose \u5141\u8bb8\u7528\u6237\u901a\u8fc7\u4e00\u4e2a <code>docker-compose.yml<\/code> \u6a21\u677f\u6587\u4ef6\uff08YAML \u683c\u5f0f\uff09\u6765\u5b9a\u4e49\u4e00\u7ec4\u76f8\u5173\u8054\u7684\u5e94\u7528\u5bb9\u5668\u4e3a\u4e00\u4e2a\u9879\u76ee\uff08project\uff09\u3002Compose \u6a21\u677f\u6587\u4ef6\u662f\u4e00\u4e2a\u5b9a\u4e49\u670d\u52a1\u3001\u7f51\u7edc\u548c\u5377\u7684 YAML \u6587\u4ef6\u3002<\/p>\n<p>Docker-Compose \u5c06\u6240\u7ba1\u7406\u7684\u5bb9\u5668\u5206\u4e3a\u4e09\u5c42\uff1a<\/p>\n<ul>\n<li><strong>\u5de5\u7a0b\uff08project\uff09<\/strong>\uff1a\u4e00\u4e2a\u5de5\u7a0b\u5305\u542b\u591a\u4e2a\u670d\u52a1\u3002\u8fd0\u884c\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\uff08docker-compose.yml \u7b49\uff09\u7ec4\u6210\u4e00\u4e2a\u5de5\u7a0b\uff0c\u82e5\u65e0\u7279\u6b8a\u6307\u5b9a\uff0c\u5de5\u7a0b\u540d\u5373\u4e3a\u5f53\u524d\u76ee\u5f55\u540d\u3002<\/li>\n<li><strong>\u670d\u52a1\uff08service\uff09<\/strong>\uff1a\u4e00\u4e2a\u670d\u52a1\u4e2d\u5b9a\u4e49\u4e86\u5bb9\u5668\u8fd0\u884c\u7684\u955c\u50cf\u3001\u53c2\u6570\u3001\u4f9d\u8d56\uff0c\u4e00\u4e2a\u670d\u52a1\u53ef\u5305\u62ec\u591a\u4e2a\u5bb9\u5668\u5b9e\u4f8b\u3002<\/li>\n<li><strong>\u5bb9\u5668\uff08container\uff09<\/strong>\uff1a\u5b9e\u9645\u8fd0\u884c\u7684\u6700\u5c0f\u5355\u5143\u5b9e\u4f8b\u3002<\/li>\n<\/ul>\n<h3>YAML \u6a21\u677f\u6587\u4ef6\u8bed\u6cd5\u6ce8\u610f\u4e8b\u9879<\/h3>\n<p>YAML \u662f\u4e00\u79cd\u6807\u8bb0\u8bed\u8a00\uff0c\u53ef\u8bfb\u6027\u9ad8\u3002\u4f7f\u7528 YAML \u65f6\u9700\u8981\u6ce8\u610f\u4e0b\u9762\u4e8b\u9879\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528\u7f29\u8fdb\u8868\u793a\u5c42\u7ea7\u5173\u7cfb\uff0c<strong>\u4e0d\u652f\u6301\u5236\u8868\u7b26 <code>tab<\/code> \u952e\u7f29\u8fdb<\/strong>\uff0c\u53ea\u80fd\u4f7f\u7528\u7a7a\u683c\u952e\u7f29\u8fdb\uff1b<\/li>\n<li>\u7f29\u8fdb\u957f\u5ea6\u6ca1\u6709\u9650\u5236\uff0c\u53ea\u8981\u5143\u7d20\u5bf9\u9f50\u5c31\u8868\u793a\u8fd9\u4e9b\u5143\u7d20\u5c5e\u4e8e\u4e00\u4e2a\u5c42\u7ea7\uff0c\u901a\u5e38\u5f00\u5934\u7f29\u8fdb 2 \u4e2a\u7a7a\u683c\uff1b<\/li>\n<li>\u5b57\u7b26\u540e\u7f29\u8fdb 1 \u4e2a\u7a7a\u683c\uff0c\u5982\u5192\u53f7 <code>: <\/code>\uff0c\u9017\u53f7 <code>, <\/code>\uff0c\u6a2a\u6760 <code>- <\/code>\uff1b<\/li>\n<li>\u7528 <code>#<\/code> \u53f7\u6ce8\u91ca\uff1b<\/li>\n<li>\u5982\u679c\u5305\u542b\u7279\u6b8a\u5b57\u7b26\u7528\u5355\u5f15\u53f7 <code>''<\/code> \u5f15\u8d77\u6765\uff0c\u5e03\u5c14\u503c\u5fc5\u987b\u7528\u5f15\u53f7 <code>\"\"<\/code> \u62ec\u8d77\u6765\uff1b<\/li>\n<li>\u533a\u5206\u5927\u5c0f\u5199\u3002<\/li>\n<\/ul>\n<h2>\u4e8c\u3001YAML \u6a21\u677f\u6587\u4ef6\u6838\u5fc3\u6307\u4ee4\u8be6\u8ff0<\/h2>\n<p>\u9ed8\u8ba4\u7684\u6a21\u677f\u6587\u4ef6\u662f <code>docker-compose.yml<\/code>\uff0c\u5176\u4e2d\u5b9a\u4e49\u7684\u6bcf\u4e2a\u670d\u52a1\u90fd\u5fc5\u987b\u901a\u8fc7 <code>image<\/code> \u6307\u4ee4\u6307\u5b9a\u955c\u50cf\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7 <code>build<\/code> \u6307\u4ee4\u81ea\u52a8\u6784\u5efa\u3002\u4ee5\u4e0b\u662f\u6240\u6709\u6838\u5fc3\u6307\u4ee4\u8be6\u89e3\uff1a<\/p>\n<h3>1\u3001image<\/h3>\n<p>\u6307\u5b9a\u4e3a\u955c\u50cf\u540d\u79f0\u6216\u955c\u50cf ID\u3002\u5982\u679c\u955c\u50cf\u4e0d\u5b58\u5728\uff0cCompose \u5c06\u5c1d\u8bd5\u4ece\u4e92\u8054\u7f51\u62c9\u53d6\u8fd9\u4e2a\u955c\u50cf\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">services:\r\n  web:\r\n    image: nginx<\/code><\/pre>\n<\/div>\n<h3>2\u3001build<\/h3>\n<p>\u6307\u5b9a Dockerfile \u6240\u5728\u6587\u4ef6\u5939\u7684\u8def\u5f84\u3002Compose \u5c06\u4f1a\u5229\u7528\u5b83\u81ea\u52a8\u6784\u5efa\u8fd9\u4e2a\u955c\u50cf\uff0c\u7136\u540e\u4f7f\u7528\u8fd9\u4e2a\u955c\u50cf\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">build: .\/dir<\/code><\/pre>\n<\/div>\n<h3>3\u3001command<\/h3>\n<p>\u8986\u76d6\u5bb9\u5668\u542f\u52a8\u540e\u9ed8\u8ba4\u6267\u884c\u7684\u547d\u4ee4\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">command: bundle exec thin -p 3000<\/code><\/pre>\n<\/div>\n<h3>4\u3001links<\/h3>\n<p>\u94fe\u63a5\u5230\u5176\u4ed6\u670d\u52a1\u5bb9\u5668\uff0c\u4f7f\u7528\u670d\u52a1\u540d\u79f0\uff08\u540c\u65f6\u4f5c\u4e3a\u522b\u540d\uff09\u6216\u670d\u52a1\u522b\u540d\uff08SERVICE:ALIAS\uff09\u90fd\u53ef\u4ee5\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">links:\r\n  - db\r\n  - db:database\r\n  - redis<\/code><\/pre>\n<\/div>\n<h3>5\u3001external_links<\/h3>\n<p>\u94fe\u63a5\u5230 docker-compose.yml \u5916\u90e8\u7684\u5bb9\u5668\uff0c\u751a\u81f3\u5e76\u975e\u662f Compose \u7ba1\u7406\u7684\u5bb9\u5668\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">external_links:\r\n  - redis_1\r\n  - project_db_1:mysql<\/code><\/pre>\n<\/div>\n<h3>6\u3001ports<\/h3>\n<p>\u66b4\u9732\u7aef\u53e3\u4fe1\u606f\u3002\u683c\u5f0f\u4e3a <code>\u5bbf\u4e3b\u673a\u5668\u7aef\u53e3:\u5bb9\u5668\u7aef\u53e3<\/code>\uff08HOST:CONTAINER\uff09\uff0c\u6216\u8005\u4ec5\u4ec5\u6307\u5b9a\u5bb9\u5668\u7684\u7aef\u53e3\uff08\u5bbf\u4e3b\u673a\u5668\u5c06\u4f1a\u968f\u673a\u5206\u914d\u7aef\u53e3\uff09\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">ports:\r\n  - &quot;3306&quot;\r\n  - &quot;8080:80&quot;\r\n  - &quot;127.0.0.1:8090:8001&quot;<\/code><\/pre>\n<\/div>\n<h3>7\u3001expose<\/h3>\n<p>\u66b4\u9732\u7aef\u53e3\uff0c\u4e0e ports \u4e0d\u540c\u7684\u662f expose <strong>\u53ea\u53ef\u4ee5\u66b4\u9732\u7aef\u53e3\u800c\u4e0d\u80fd\u6620\u5c04\u5230\u4e3b\u673a<\/strong>\uff0c\u53ea\u4f9b\u5916\u90e8\u670d\u52a1\u8fde\u63a5\u4f7f\u7528\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">expose:\r\n  - &quot;3000&quot;\r\n  - &quot;8000&quot;<\/code><\/pre>\n<\/div>\n<h3>8\u3001volumes<\/h3>\n<p>\u8bbe\u7f6e\u5377\u6302\u8f7d\u7684\u8def\u5f84\u3002\u53ef\u4ee5\u8bbe\u7f6e <code>\u5bbf\u4e3b\u673a\u8def\u5f84:\u5bb9\u5668\u8def\u5f84<\/code>\uff08host:container\uff09\u6216\u52a0\u4e0a\u8bbf\u95ee\u6a21\u5f0f\uff08host:container:ro\uff09\u3002ro \u662f readonly \u6a21\u5f0f\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">volumes:\r\n  - \/var\/lib\/mysql:\/var\/lib\/mysql\r\n  - \/configs\/mysql:\/etc\/configs\/:ro<\/code><\/pre>\n<\/div>\n<h3>9\u3001volumes_from<\/h3>\n<p>\u6302\u8f7d\u53e6\u4e00\u4e2a\u670d\u52a1\u6216\u5bb9\u5668\u7684\u6240\u6709\u6570\u636e\u5377\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">volumes_from:\r\n  - service_name\r\n  - container_name<\/code><\/pre>\n<\/div>\n<h3>10\u3001environment<\/h3>\n<p>\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u53ef\u4ee5\u5c5e\u4e8e\u6570\u7ec4\u6216\u5b57\u5178\u4e24\u79cd\u683c\u5f0f\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">environment:\r\n  - RACK_ENV=development\r\n  - SESSION_SECRET<\/code><\/pre>\n<\/div>\n<h3>11\u3001env_file<\/h3>\n<p>\u4ece\u6587\u4ef6\u4e2d\u83b7\u53d6\u73af\u5883\u53d8\u91cf\uff0c\u53ef\u4ee5\u4e3a\u5355\u72ec\u7684\u6587\u4ef6\u8def\u5f84\u6216\u5217\u8868\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">env_file: .env\r\nenv_file:\r\n  - .\/common.env\r\n  - \/opt\/secrets.env<\/code><\/pre>\n<\/div>\n<h3>12\u3001extends<\/h3>\n<p>\u57fa\u4e8e\u5df2\u6709\u7684\u670d\u52a1\u8fdb\u884c\u670d\u52a1\u6269\u5c55\u3002\u81ea\u52a8\u7ee7\u627f common.yml \u4e2d\u7684 webapp \u670d\u52a1\u53ca\u76f8\u5173\u7684\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">web:\r\n  extends:\r\n    file: common.yml\r\n    service: webapp<\/code><\/pre>\n<\/div>\n<h3>13\u3001net<\/h3>\n<p>\u8bbe\u7f6e\u7f51\u7edc\u6a21\u5f0f\u3002\u4f7f\u7528\u548c docker client \u7684 &#8211;net \u53c2\u6570\u4e00\u6837\u7684\u503c\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">net: &quot;bridge&quot; # \u5bb9\u5668\u9ed8\u8ba4\u8fde\u63a5\u7684\u7f51\u7edc\uff0c\u5373\u9ed8\u8ba4\u7684 docker0 \u7f51\u7edc\r\nnet: &quot;none&quot; # \u5bb9\u5668\u5b9a\u5236\u7684\u7f51\u7edc\u6808\r\nnet: &quot;container:[name or id]&quot; # \u4f7f\u7528\u53e6\u4e00\u4e2a\u5bb9\u5668\u7684\u7f51\u7edc\u914d\u7f6e\r\nnet: &quot;host&quot; # \u5728\u5bbf\u4e3b\u7f51\u7edc\u6808\u4e0a\u6dfb\u52a0\u4e00\u4e2a\u5bb9\u5668<\/code><\/pre>\n<\/div>\n<h3>14\u3001pid<\/h3>\n<p>\u548c\u5bbf\u4e3b\u673a\u7cfb\u7edf\u5171\u4eab\u8fdb\u7a0b\u547d\u540d\u7a7a\u95f4\uff0c\u6253\u5f00\u8be5\u9009\u9879\u7684\u5bb9\u5668\u53ef\u4ee5\u76f8\u4e92\u901a\u8fc7\u8fdb\u7a0b ID \u6765\u8bbf\u95ee\u548c\u64cd\u4f5c\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">pid: &quot;host&quot;<\/code><\/pre>\n<\/div>\n<h3>15\u3001dns \/ dns_search<\/h3>\n<p>\u914d\u7f6e DNS \u670d\u52a1\u5668\u53ca DNS \u641c\u7d22\u57df\u3002\u53ef\u4ee5\u662f\u5355\u4e2a\u503c\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u5217\u8868\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">dns:\r\n  - 8.8.8.8\r\n  - 9.9.9.9\r\ndns_search:\r\n  - domain1.example.com<\/code><\/pre>\n<\/div>\n<h3>16\u3001cap_add \/ cap_drop<\/h3>\n<p>\u6dfb\u52a0\u6216\u653e\u5f03\u5bb9\u5668\u7684 Linux \u80fd\u529b\uff08Capability\uff09\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">cap_add:\r\n  - ALL\r\ncap_drop:\r\n  - NET_ADMIN<\/code><\/pre>\n<\/div>\n<h3>17\u3001healthcheck<\/h3>\n<p>\u5065\u5eb7\u68c0\u67e5\uff0c\u975e\u5e38\u6709\u5fc5\u8981\uff0c\u7b49\u670d\u52a1\u51c6\u5907\u597d\u4ee5\u540e\u518d\u4e0a\u7ebf\uff0c\u907f\u514d\u66f4\u65b0\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u77ed\u6682\u7684\u65e0\u6cd5\u8bbf\u95ee\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">healthcheck:\r\n  test: [&quot;CMD&quot;, &quot;curl&quot;, &quot;-f&quot;, &quot;http:\/\/localhost\/alive&quot;]\r\n  interval: 5s\r\n  timeout: 3s<\/code><\/pre>\n<\/div>\n<h3>18\u3001depends_on<\/h3>\n<p>\u4f9d\u8d56\u7684\u670d\u52a1\uff0c\u4f18\u5148\u542f\u52a8\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">depends_on:\r\n  - redis<\/code><\/pre>\n<\/div>\n<h3>19\u3001deploy<\/h3>\n<p>\u90e8\u7f72\u76f8\u5173\u7684\u914d\u7f6e\uff08\u5982\u5728 swarm \u6a21\u5f0f\u4e0b\uff09\u3002\u53ef\u4ee5\u914d\u7f6e\u526f\u672c\u6570\u91cf\u3001\u8d44\u6e90\u9650\u5236\u7b49\u3002<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">deploy:\r\n  mode: replicated\r\n  replicas: 2\r\n  restart_policy:\r\n    condition: on-failure\r\n    max_attempts: 3\r\n  resources:\r\n    limits:\r\n      cpus: &quot;0.50&quot;\r\n      memory: 1g<\/code><\/pre>\n<\/div>\n<h2>\u4e09\u3001\u5b8c\u6574 docker-compose.yml \u5b9e\u4f8b (Nacos \u9ad8\u53ef\u7528\u96c6\u7fa4)<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4f7f\u7528 Docker-Compose \u7f16\u6392 Nacos \u96c6\u7fa4\u7684\u5177\u4f53\u6848\u4f8b\uff1a<\/p>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">YAML<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-yaml\">version: &#039;3.5&#039;\r\nservices:\r\n  nacos1:\r\n    restart: always\r\n    image: nacos\/nacos-server:${NACOS_VERSION}\r\n    container_name: nacos1\r\n    privileged: true\r\n    ports:\r\n      - &quot;8001:8001&quot;\r\n      - &quot;8011:9555&quot;\r\n    deploy:\r\n      resources:\r\n        limits:\r\n          cpus: &#039;0.50&#039;\r\n          memory: 1024M\r\n    env_file:\r\n      - .\/nacos.env\r\n    environment:\r\n      NACOS_SERVER_IP: ${NACOS_SERVER_IP_1}\r\n      NACOS_APPLICATION_PORT: 8001\r\n      NACOS_SERVERS: ${NACOS_SERVERS}\r\n    volumes:\r\n      - .\/logs_01\/:\/home\/nacos\/logs\/\r\n      - .\/data_01\/:\/home\/nacos\/data\/\r\n      - .\/config\/:\/home\/nacos\/config\/\r\n    networks:\r\n      - ha-network-overlay\r\nnetworks:\r\n  ha-network-overlay:\r\n    external: true<\/code><\/pre>\n<\/div>\n<h2>\u56db\u3001Docker-Compose \u5e38\u7528\u547d\u4ee4\u8be6\u7ec6\u6e05\u5355<\/h2>\n<h3>1. docker-compose \u547d\u4ee4\u683c\u5f0f<\/h3>\n<div class=\"xun-code-wrapper\">\n<div class=\"xun-code-header\">\n<div class=\"xun-code-header-left\"><span class=\"xun-code-dots\"><span><\/span><span><\/span><span><\/span><\/span><\/div>\n<div class=\"xun-code-header-right\"><span class=\"xun-code-lang\">Bash\/Shell<\/span><button type=\"button\" class=\"xun-code-copy\" title=\"\u590d\u5236\u4ee3\u7801\"><svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\"><\/path><\/svg><\/button><\/div>\n<\/div>\n<pre class=\"xun-code-block line-numbers\" ><code class=\"language-bash\">docker-compose [-f &lt;arg&gt;...] [options] [COMMAND] [ARGS...]<\/code><\/pre>\n<\/div>\n<ul>\n<li><code>-f, --file<\/code>: \u6307\u5b9a Compose \u6a21\u677f\u6587\u4ef6\uff0c\u9ed8\u8ba4\u4e3a docker-compose.yml\uff0c\u53ef\u4ee5\u591a\u6b21\u6307\u5b9a\u3002<\/li>\n<li><code>-p, --project-name<\/code>: \u6307\u5b9a\u9879\u76ee\u540d\u79f0\uff0c\u9ed8\u8ba4\u4f7f\u7528\u6240\u5728\u76ee\u5f55\u540d\u79f0\u4f5c\u4e3a\u9879\u76ee\u540d\u3002<\/li>\n<\/ul>\n<h3>2. docker-compose up<\/h3>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u4e00\u5b9a\u8981\u8bb0\u4f4f\uff0c\u6bcf\u6b21\u542f\u52a8\u90fd\u8981\u7528\u5230\u3002<\/p>\n<ul>\n<li><code>-d<\/code>: \u5728\u540e\u53f0\u8fd0\u884c\u670d\u52a1\u5bb9\u5668\u3002<\/li>\n<li><code>--force-recreate<\/code>: \u5f3a\u5236\u91cd\u65b0\u521b\u5efa\u5bb9\u5668\uff0c\u4e0d\u80fd\u4e0e &#8211;no-recreate \u540c\u65f6\u4f7f\u7528\u3002<\/li>\n<li><code>--build<\/code>: \u5728\u542f\u52a8\u5bb9\u5668\u524d\u6784\u5efa\u670d\u52a1\u955c\u50cf\u3002<\/li>\n<\/ul>\n<h3>3. docker-compose ps<\/h3>\n<p>\u5217\u51fa\u9879\u76ee\u4e2d\u76ee\u524d\u7684\u6240\u6709\u5bb9\u5668\u3002<\/p>\n<h3>4. docker-compose stop \/ start<\/h3>\n<ul>\n<li><code>docker-compose stop<\/code>: \u505c\u6b62\u6b63\u5728\u8fd0\u884c\u7684\u5bb9\u5668\uff0c\u53ef\u4ee5\u901a\u8fc7 <code>start<\/code> \u518d\u6b21\u542f\u52a8\u3002<\/li>\n<li><code>docker-compose start<\/code>: \u542f\u52a8\u5df2\u7ecf\u5b58\u5728\u7684\u670d\u52a1\u5bb9\u5668\u3002<\/li>\n<\/ul>\n<h3>5. docker-compose down<\/h3>\n<p>\u505c\u6b62\u548c\u5220\u9664\u5bb9\u5668\u3001\u7f51\u7edc\u3001\u5377\u3001\u955c\u50cf\u3002<\/p>\n<ul>\n<li><code>--rmi type<\/code>: \u5220\u9664\u955c\u50cf\u3002all \u5220\u9664\u5b9a\u4e49\u7684\u6240\u6709\u955c\u50cf\uff1blocal \u5220\u9664\u955c\u50cf\u540d\u4e3a\u7a7a\u7684\u955c\u50cf\u3002<\/li>\n<li><code>-v, --volumes<\/code>: \u5220\u9664\u5df2\u7ecf\u5728 compose \u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684\u548c\u533f\u540d\u7684\u9644\u5728\u5bb9\u5668\u4e0a\u7684\u6570\u636e\u5377\u3002<\/li>\n<\/ul>\n<h3>6. docker-compose logs<\/h3>\n<p>\u67e5\u770b\u670d\u52a1\u5bb9\u5668\u7684\u8f93\u51fa\u65e5\u5fd7\u3002\u53ef\u4ee5\u901a\u8fc7 <code>-f<\/code> \u53c2\u6570\u5b9e\u73b0\u5b9e\u65f6\u8ddf\u8e2a\uff08\u7c7b\u4f3c\u4e8e tail -f\uff09\u3002<\/p>\n<h3>7. docker-compose build<\/h3>\n<p>\u6784\u5efa\uff08\u91cd\u65b0\u6784\u5efa\uff09\u9879\u76ee\u4e2d\u7684\u670d\u52a1\u5bb9\u5668\u3002\u4f7f\u7528 <code>--no-cache<\/code> \u53ef\u4ee5\u4e0d\u4f7f\u7528\u7f13\u5b58\u6784\u5efa\u3002<\/p>\n<h3>8. docker-compose pull<\/h3>\n<p>\u62c9\u53d6\u670d\u52a1\u4f9d\u8d56\u7684\u955c\u50cf\u3002<\/p>\n<h3>9. docker-compose restart<\/h3>\n<p>\u91cd\u542f\u9879\u76ee\u4e2d\u7684\u670d\u52a1\u3002\u53ef\u4ee5\u901a\u8fc7 <code>-t<\/code> \u6307\u5b9a\u91cd\u542f\u524d\u505c\u6b62\u5bb9\u5668\u7684\u8d85\u65f6\u65f6\u95f4\u3002<\/p>\n<h3>10. docker-compose rm<\/h3>\n<p>\u5220\u9664\u6240\u6709\uff08\u505c\u6b62\u72b6\u6001\u7684\uff09\u670d\u52a1\u5bb9\u5668\u3002\u63a8\u8350\u5148\u6267\u884c stop \u547d\u4ee4\u518d\u6267\u884c rm\u3002<\/p>\n<ul>\n<li><code>-f<\/code>: \u5f3a\u5236\u76f4\u63a5\u5220\u9664\uff0c\u5305\u62ec\u975e\u505c\u6b62\u72b6\u6001\u7684\u5bb9\u5668\u3002<\/li>\n<\/ul>\n<h3>11. docker-compose run<\/h3>\n<p>\u5728\u6307\u5b9a\u670d\u52a1\u4e0a\u6267\u884c\u4e00\u4e2a\u547d\u4ee4\u3002\u4f8b\u5982 <code>docker-compose run --rm web python manage.py migrate<\/code>\uff08\u6267\u884c\u5b8c\u6bd5\u540e\u81ea\u52a8\u5220\u9664\u4e34\u65f6\u5bb9\u5668\uff09\u3002<\/p>\n<h3>12. docker-compose scale<\/h3>\n<p>\u8bbe\u7f6e\u6307\u5b9a\u670d\u52a1\u8fd0\u884c\u7684\u5bb9\u5668\u4e2a\u6570\uff0c\u4f8b\u5982 <code>docker-compose scale web=3 db=2<\/code>\u3002<\/p>\n<h3>13. docker-compose pause \/ unpause<\/h3>\n<p>\u6682\u505c\u6216\u6062\u590d\u4e00\u4e2a\u670d\u52a1\u5bb9\u5668\u3002<\/p>\n<h3>14. docker-compose kill<\/h3>\n<p>\u901a\u8fc7\u53d1\u9001 <code>SIGKILL<\/code> \u4fe1\u53f7\u6765\u5f3a\u5236\u505c\u6b62\u670d\u52a1\u5bb9\u5668\u3002\u652f\u6301\u901a\u8fc7 <code>-s<\/code> \u53c2\u6570\u6307\u5b9a\u53d1\u9001\u7684\u4fe1\u53f7\u3002<\/p>\n<h3>15. docker-compose config<\/h3>\n<p>\u9a8c\u8bc1\u5e76\u67e5\u770b compose \u6587\u4ef6\u914d\u7f6e\u3002\u5f53\u914d\u7f6e\u6b63\u786e\u65f6\uff0c\u4e0d\u8f93\u51fa\u4efb\u4f55\u5185\u5bb9\uff0c\u5f53\u6587\u4ef6\u914d\u7f6e\u9519\u8bef\u65f6\uff0c\u8f93\u51fa\u5177\u4f53\u7684\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Docker-Compose \u8bb2\u89e3 Docker-Compose \u9879\u76ee\u662f Docker \u5b98\u65b9\u7684\u5f00\u6e90\u9879\u76ee\uff0c\u8d1f\u8d23\u5b9e<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"special":[],"class_list":["post-49","post","type-post","status-publish","format-standard","hentry","category-article"],"_links":{"self":[{"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=49"}],"version-history":[{"count":1,"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=\/wp\/v2\/posts\/49\/revisions"}],"predecessor-version":[{"id":50,"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=\/wp\/v2\/posts\/49\/revisions\/50"}],"wp:attachment":[{"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=49"},{"taxonomy":"special","embeddable":true,"href":"https:\/\/hi.tionmon.de\/index.php?rest_route=%2Fwp%2Fv2%2Fspecial&post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}