{"id":11089,"date":"2022-11-10T16:11:44","date_gmt":"2022-11-10T08:11:44","guid":{"rendered":"https:\/\/www.lwops.cn\/?p=11089"},"modified":"2022-11-10T16:12:47","modified_gmt":"2022-11-10T08:12:47","slug":"zabbix%e6%8a%80%e6%9c%af%e5%88%86%e4%ba%ab-%e4%bd%bf%e7%94%a8docker-compose%e5%bf%ab%e9%80%9f%e9%83%a8%e7%bd%b2zabbix%e7%9b%91%e6%8e%a7%e7%b3%bb%e7%bb%9f","status":"publish","type":"post","link":"https:\/\/www.lwops.cn\/index.php\/interflow\/technology\/11089","title":{"rendered":"zabbix\u6280\u672f\u5206\u4eab\u2014\u2014\u4f7f\u7528docker-compose\u5feb\u901f\u90e8\u7f72zabbix\u76d1\u63a7\u7cfb\u7edf"},"content":{"rendered":"\n
\u524d\u9762\u4e50\u7ef4\u541b\u6709\u63d0\u5230\u8fc7\u4f7f\u7528docker\u6765\u5feb\u901f\u62c9\u8d77\u4e00\u4e2azabbix\u76d1\u63a7\u7cfb\u7edf\uff08\u8be6\u89c1\uff1a\u5982\u4f55\u4f7f\u7528docker\u5feb\u901f\u90e8\u7f72\u4e00\u4e2azabbix\u76d1\u63a7\u7cfb\u7edf<\/u><\/a>\uff09\uff0c\u4f46\u662f\u8981\u4e00\u4e2a\u4e2a\u6267\u884cdocker\u542f\u52a8\u547d\u4ee4\u53bb\u5c06\u5bf9\u5e94\u7684\u5bb9\u5668\u542f\u52a8\u3002\u5982\u679c\u8981\u914d\u7f6e\u53c2\u6570\u591a\uff0c\u90a3\u6572\u542f\u52a8\u547d\u4ee4\u5c31\u662f\u4e00\u4ef6\u8ba9\u4eba\u5fc3\u7d2f\u7684\u4e8b\u60c5\u3002\u800c\u4e14\u6572\u5b8c\u540e\u82e5\u6ca1\u6709\u4fdd\u5b58\u542f\u52a8\u547d\u4ee4\uff0c\u540e\u9762\u7684\u7ba1\u7406\u4e5f\u662f\u6bd4\u8f83\u9ebb\u70e6\uff0c\u5e76\u4e14\u5982\u679c\u5bb9\u5668\u6570\u91cf\u8f83\u591a\uff0c\u8fd8\u8981\u4e00\u4e2a\u4e2a\u624b\u6572\u542f\u52a8\u547d\u4ee4\uff0c\u8fd9\u5c31\u975e\u5e38\u7684\u4e0d\u65b9\u4fbf\u3002<\/p>\n\n\n\n \u6240\u4ee5\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u5e76\u4e14\u66f4\u52a0\u9ad8\u6548\u7684\u542f\u52a8\u4e00\u4e2azabbix\u76d1\u63a7\u7cfb\u7edf\u3002\u73b0\u5728\u4f7f\u7528docker-compose\u8fd9\u4e2a\u5bb9\u5668\u7f16\u6392\u5de5\u5177\u6765\u9ad8\u6548\u7684\u542f\u52a8zabbix\u76d1\u63a7\u7cfb\u7edf<\/a>\u3002<\/p>\n\n\n\n Docker-Compose\u9879\u76ee\u662fDocker\u5b98\u65b9\u7684\u5f00\u6e90\u9879\u76ee\uff0c\u8d1f\u8d23\u5b9e\u73b0\u5bf9Docker\u5bb9\u5668\u96c6\u7fa4\u7684\u5feb\u901f\u7f16\u6392, \u5e76\u4e14\u63d0\u4f9b\u4e86 scale (\u670d\u52a1\u6269\u5bb9) \u7684\u529f\u80fd\u3002<\/p>\n\n\n\n Docker-Compose\u5c06\u6240\u7ba1\u7406\u7684\u5bb9\u5668\u5206\u4e3a\u4e09\u5c42\uff0c\u5206\u522b\u662f\u5de5\u7a0b\uff08project\uff09\uff0c\u670d\u52a1\uff08service\uff09\u4ee5\u53ca\u5bb9\u5668\uff08container\uff09\u3002Docker-Compose\u8fd0\u884c\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\uff08docker-compose.yml\uff0cextends\u6587\u4ef6\u6216\u73af\u5883\u53d8\u91cf\u6587\u4ef6\u7b49\uff09\u7ec4\u6210\u4e00\u4e2a\u5de5\u7a0b\uff0c\u82e5\u65e0\u7279\u6b8a\u6307\u5b9a\u5de5\u7a0b\u540d\u5373\u4e3a\u5f53\u524d\u76ee\u5f55\u540d\u3002\u4e00\u4e2a\u5de5\u7a0b\u5f53\u4e2d\u53ef\u5305\u542b\u591a\u4e2a\u670d\u52a1\uff0c\u6bcf\u4e2a\u670d\u52a1\u4e2d\u5b9a\u4e49\u4e86\u5bb9\u5668\u8fd0\u884c\u7684\u955c\u50cf\uff0c\u53c2\u6570\uff0c\u4f9d\u8d56\u3002\u4e00\u4e2a\u670d\u52a1\u5f53\u4e2d\u53ef\u5305\u62ec\u591a\u4e2a\u5bb9\u5668\u5b9e\u4f8b\uff0cDocker-Compose\u5e76\u6ca1\u6709\u89e3\u51b3\u8d1f\u8f7d\u5747\u8861\u7684\u95ee\u9898\uff0c\u56e0\u6b64\u9700\u8981\u501f\u52a9\u5176\u5b83\u5de5\u5177\u5b9e\u73b0\u670d\u52a1\u53d1\u73b0\u53ca\u8d1f\u8f7d\u5747\u8861\u3002<\/p>\n\n\n\n Docker-Compose\u7684\u5de5\u7a0b\u914d\u7f6e\u6587\u4ef6\u9ed8\u8ba4\u4e3adocker-compose.yml\uff0c\u53ef\u901a\u8fc7\u73af\u5883\u53d8\u91cfCOMPOSE_FILE\u6216-f\u53c2\u6570\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6\uff0c\u5176\u5b9a\u4e49\u4e86\u591a\u4e2a\u6709\u4f9d\u8d56\u5173\u7cfb\u7684\u670d\u52a1\u53ca\u6bcf\u4e2a\u670d\u52a1\u8fd0\u884c\u7684\u5bb9\u5668\u3002<\/p>\n\n\n\n \u4f7f\u7528\u4e00\u4e2aDockerfile\u6a21\u677f\u6587\u4ef6\uff0c\u53ef\u4ee5\u8ba9\u7528\u6237\u5f88\u65b9\u4fbf\u7684\u5b9a\u4e49\u4e00\u4e2a\u5355\u72ec\u7684\u5e94\u7528\u5bb9\u5668\u3002\u5728\u5de5\u4f5c\u4e2d\uff0c\u7ecf\u5e38\u4f1a\u78b0\u5230\u9700\u8981\u591a\u4e2a\u5bb9\u5668\u76f8\u4e92\u914d\u5408\u6765\u5b8c\u6210\u67d0\u9879\u4efb\u52a1\u7684\u60c5\u51b5\u3002\u4f8b\u5982\u8981\u5b9e\u73b0\u4e00\u4e2aWeb\u9879\u76ee\uff0c\u9664\u4e86Web\u670d\u52a1\u5bb9\u5668\u672c\u8eab\uff0c\u5f80\u5f80\u8fd8\u9700\u8981\u518d\u52a0\u4e0a\u540e\u7aef\u7684\u6570\u636e\u5e93\u670d\u52a1\u5bb9\u5668\uff0c\u751a\u81f3\u8fd8\u5305\u62ec\u8d1f\u8f7d\u5747\u8861\u5bb9\u5668\u7b49\u3002<\/p>\n\n\n\n Compose\u5141\u8bb8\u7528\u6237\u901a\u8fc7\u4e00\u4e2a\u5355\u72ec\u7684docker-compose.yml\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\u3002<\/p>\n\n\n\n Docker-Compose\u9879\u76ee\u7531Python\u7f16\u5199\uff0c\u8c03\u7528Docker\u670d\u52a1\u63d0\u4f9b\u7684API\u6765\u5bf9\u5bb9\u5668\u8fdb\u884c\u7ba1\u7406\u3002\u56e0\u6b64\uff0c\u53ea\u8981\u6240\u64cd\u4f5c\u7684\u5e73\u53f0\u652f\u6301Docker API\uff0c\u5c31\u53ef\u4ee5\u5728\u5176\u4e0a\u5229\u7528Compose\u6765\u8fdb\u884c\u7f16\u6392\u7ba1\u7406\u3002<\/p>\n\n\n\n Docker-compose\u5c31\u662f\u901a\u8fc7docker-compose.yaml\u6587\u4ef6\u6240\u5b9a\u4e49\u7684\u5bb9\u5668\u4f5c\u4e3a\u4e00\u4e2a\u9879\u76ee\uff0c\u4ece\u800c\u8fdb\u884cdocker\u5bb9\u5668\u7684\u7ba1\u7406\u3002\u4e0b\u9762\u5c31\u5bf9docker-compose.yaml\u6a21\u677f\u6587\u4ef6\u7684\u5e38\u7528\u57fa\u7840\u8bed\u6cd5\u8fdb\u884c\u4e00\u4e2a\u7b80\u5355\u7684\u89e3\u91ca<\/p>\n\n\n\n Compose \u7684\u5bb9\u5668\u9ed8\u8ba4\u540d\u79f0\u683c\u5f0f\u662f\uff1a<\u9879\u76ee\u540d\u79f0><\u670d\u52a1\u540d\u79f0><\u5e8f\u53f7><\/p>\n\n\n\n \u867d\u7136\u53ef\u4ee5\u81ea\u5b9a\u4e49\u9879\u76ee\u540d\u79f0\u3001\u670d\u52a1\u540d\u79f0\uff0c\u4f46\u662f\u5982\u679c\u4f60\u60f3\u5b8c\u5168\u63a7\u5236\u5bb9\u5668\u7684\u547d\u540d\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u6807\u7b7e\u6307\u5b9a\uff1a<\/p>\n\n\n\n \u6bd4\u5982\u6211\u8981\u5236\u5b9a\u4e00\u4e2amysql\u5bb9\u5668\u7684\u540d\u4e3a\u201cmysql-test\u201d,\u90a3\u4e48<\/p>\n\n\n\n version: ‘3’<\/p>\n\n\n\n services:<\/p>\n\n\n\n mysql:<\/p>\n\n\n\n container_name: mysql-test<\/p>\n\n\n\n \u6307\u5b9a\u670d\u52a1\u7684\u955c\u50cf\u540d\u79f0\u6216\u955c\u50cf ID\u3002\u5982\u679c\u955c\u50cf\u5728\u672c\u5730\u4e0d\u5b58\u5728\uff0cCompose \u5c06\u4f1a\u5c1d\u8bd5\u62c9\u53d6\u8fd9\u4e2a\u955c\u50cf\u3002<\/p>\n\n\n\n \u6bd4\u5982\u6211\u8981\u5236\u5b9a\u4e00\u4e2amysql\u5bb9\u5668,\u4f7f\u7528\u7684\u955c\u50cf\u540d\u4e3a\u201cmysql:8.0\u201d,\u90a3\u4e48<\/p>\n\n\n\n version: ‘3’<\/p>\n\n\n\n services:<\/p>\n\n\n\n mysql:<\/p>\n\n\n\n image: mysql:8.0<\/p>\n\n\n\n \u5728\u4f7f\u7528 Compose \u65f6\uff0c\u6700\u5927\u7684\u597d\u5904\u5c31\u662f\u5c11\u6253\u542f\u52a8\u547d\u4ee4\uff0c\u4f46\u662f\u4e00\u822c\u9879\u76ee\u5bb9\u5668\u542f\u52a8\u7684\u987a\u5e8f\u662f\u6709\u8981\u6c42\u7684\uff0c\u5982\u679c\u76f4\u63a5\u4ece\u4e0a\u5230\u4e0b\u542f\u52a8\u5bb9\u5668\uff0c\u5fc5\u7136\u4f1a\u56e0\u4e3a\u5bb9\u5668\u4f9d\u8d56\u95ee\u9898\u800c\u542f\u52a8\u5931\u8d25\u3002<\/p>\n\n\n\n \u4f8b\u5982\u5728\u6ca1\u542f\u52a8\u6570\u636e\u5e93\u5bb9\u5668\u7684\u65f6\u5019\u542f\u52a8\u4e86\u5e94\u7528\u5bb9\u5668\uff0c\u8fd9\u65f6\u5019\u5e94\u7528\u5bb9\u5668\u4f1a\u56e0\u4e3a\u627e\u4e0d\u5230\u6570\u636e\u5e93\u800c\u9000\u51fa\uff0c\u4e3a\u4e86\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\u6211\u4eec\u9700\u8981\u52a0\u5165\u4e00\u4e2a\u6807\u7b7e\uff0c\u5c31\u662f depends_on\uff0c\u8fd9\u4e2a\u6807\u7b7e\u89e3\u51b3\u4e86\u5bb9\u5668\u7684\u4f9d\u8d56\u3001\u542f\u52a8\u5148\u540e\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n \u6bd4\u5982\u6211\u8981\u5148\u542f\u52a8\u4e00\u4e2aMySQL\uff0c\u540e\u542f\u52a8nginx\uff0c\u90a3\u4e48<\/p>\n\n\n\n version: ‘3’<\/p>\n\n\n\n services:<\/p>\n\n\n\n nginx:<\/p>\n\n\n\n image: nginx:1.16.1<\/p>\n\n\n\n depends_on:<\/p>\n\n\n\n – mysql<\/p>\n\n\n\n mysql:<\/p>\n\n\n\n \u00a0\u00a0\u00a0\u00a0image: mysql:8.0<\/p>\n\n\n\n \u8fd9\u662f\u8bbe\u7f6e\u955c\u50cf\u7684\u73af\u5883\u53d8\u91cf\uff0c\u76f4\u63a5\u5c06\u53d8\u91cf\u5b9a\u4e49\u5230\u955c\u50cf\u91cc\u9762\uff0c\u8fd9\u6837\u542f\u52a8\u5bb9\u5668\u65f6\u4f1a\u81ea\u52a8\u8bfb\u53d6\u8be5\u73af\u5883\u53d8\u91cf<\/p>\n\n\n\n \u5982\u542f\u52a8\u4e00\u4e2aMySQL\u5bb9\u5668\uff0c\u8981\u8bbe\u7f6e\u5b83\u7684root\u521d\u59cb\u5316\u5bc6\u7801\u4e3a\u201c123456\u201d\uff0c\u90a3<\/p>\n\n\n\n version: ‘3’<\/p>\n\n\n\n services:<\/p>\n\n\n\n mysql:<\/p>\n\n\n\n image: mysql:8.0<\/p>\n\n\n\n environment:<\/p>\n\n\n\n \u00a0\u00a0MYSQL_ROOT_PASSWORD: 123456<\/p>\n\n\n\n \u8be5\u53c2\u6570\u662f\u5c06\u5bbf\u4e3b\u673a\u7684\u7aef\u53e3\u6620\u5c04\u5230\u5bb9\u5668\u7aef\u53e3\uff0c\u4ece\u800c\u5728\u5bbf\u4e3b\u673a\u8bbf\u95ee\u5bf9\u5e94\u7684\u7aef\u53e3\u80fd\u8bbf\u95ee\u5230\u5bb9\u5668\u5185\u3002<\/p>\n\n\n\n \u5982\u8981\u8bb2MySQL\u5bb9\u5668\u76843306\u7aef\u53e3\u6620\u5c04\u5230\u5bbf\u4e3b\u673a\u768433060\u7aef\u53e3\uff0c\u90a3<\/p>\n\n\n\n version: ‘3’<\/p>\n\n\n\n services:<\/p>\n\n\n\n mysql:<\/p>\n\n\n\n image: mysql:8.0<\/p>\n\n\n\n ports:-\u201c33060:3306\u201d<\/p>\n\n\n\n \u6302\u8f7d\u4e00\u4e2a\u76ee\u5f55\u6216\u8005\u4e00\u4e2a\u5df2\u5b58\u5728\u7684\u6570\u636e\u5377\u5bb9\u5668\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 [HOST:CONTAINER] \u8fd9\u6837\u7684\u683c\u5f0f\uff0c\u6216\u8005\u4f7f\u7528 [HOST:CONTAINER:ro] \u8fd9\u6837\u7684\u683c\u5f0f\uff0c\u540e\u8005\u5bf9\u4e8e\u5bb9\u5668\u6765\u8bf4\uff0c\u6570\u636e\u5377\u662f\u53ea\u8bfb\u7684\uff0c\u8fd9\u6837\u53ef\u4ee5\u6709\u6548\u4fdd\u62a4\u5bbf\u4e3b\u673a\u7684\u6587\u4ef6\u7cfb\u7edf\u3002 Compose\u7684\u6570\u636e\u5377\u6307\u5b9a\u8def\u5f84\u53ef\u4ee5\u662f\u76f8\u5bf9\u8def\u5f84\uff0c\u4f7f\u7528 . \u6216\u8005 .. \u6765\u6307\u5b9a\u76f8\u5bf9\u76ee\u5f55\u3002 version: ‘3’ services: mysql: image: mysql:8.0 volumes: -.\/data:\/var\/lib\/mysql -\/var\/log\/mysql:\/var\/log\/mysql<\/p>\n\n\n\n \u9009\u62e9\u5bf9\u5e94\u7248\u672c\u4e0b\u8f7d\u5b89\u88c5\u5305<\/p>\n\n\n\n https:\/\/github.com\/docker\/compose\/releases?after=1.28.0<\/a><\/p>\n\n\n\n1.\u00a0Docker-compose\u4ecb\u7ecd<\/strong><\/h3>\n\n\n\n
2.\u00a0\u57fa\u7840\u8bed\u6cd5<\/strong><\/h3>\n\n\n\n
2.1.\u00a0container_name<\/strong><\/h2>\n\n\n\n
2.2.\u00a0image<\/strong><\/h2>\n\n\n\n
2.3.\u00a0depends_on<\/strong><\/h2>\n\n\n\n
2.4.\u00a0environment<\/strong><\/h2>\n\n\n\n
2.5.\u00a0ports<\/strong><\/h2>\n\n\n\n
2.6.\u00a0volumes<\/strong><\/h2>\n\n\n\n
3.\u00a0\u5b89\u88c5docker-compose<\/strong><\/h3>\n\n\n\n