{"id":11547,"date":"2023-07-20T09:29:28","date_gmt":"2023-07-20T01:29:28","guid":{"rendered":"http:\/\/92it.top\/?p=11547"},"modified":"2025-06-27T09:34:25","modified_gmt":"2025-06-27T01:34:25","slug":"%e8%bf%9b%e5%85%a5docker%e5%ae%b9%e5%99%a8%e7%9a%84%e6%ad%a3%e7%a1%ae%e5%a7%bf%e5%8a%bf","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=11547","title":{"rendered":"\u8fdb\u5165Docker\u5bb9\u5668\u7684\u6b63\u786e\u59ff\u52bf"},"content":{"rendered":"\n<p><strong>1.1\u3001Docker\u5bb9\u5668\u662f\u4ec0\u4e48<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p><code>Docker<\/code>\u5bb9\u5668\u8fd0\u884c\u8d77\u6765\u672c\u8d28\u4e0a\u5c31\u662f\u5bbf\u4e3b\u673a\u91cc\u9762\u7684\u4e00\u4e2a\u8fdb\u7a0b\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>1.2\u3001\u5bb9\u5668\u7684\u76f8\u5173\u64cd\u4f5c<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u64cd\u4f5c<\/th><th>\u4f5c\u7528<\/th><\/tr><\/thead><tbody><tr><td><a href=\"http:\/\/blog.fpliu.com\/it\/software\/docker\/command\/run\">docker run<\/a><\/td><td>\u521b\u5efa\u3001\u542f\u52a8\u4e00\u4e2a\u5bb9\u5668<\/td><\/tr><tr><td><a href=\"http:\/\/blog.fpliu.com\/it\/software\/docker\/command\/start\">docker start<\/a><\/td><td>\u542f\u52a8\u6307\u5b9a\u5bb9\u5668<\/td><\/tr><tr><td><a href=\"http:\/\/blog.fpliu.com\/it\/software\/docker\/command\/restart\">docker restart<\/a><\/td><td>\u91cd\u65b0\u542f\u52a8\u6307\u5b9a\u5bb9\u5668<\/td><\/tr><tr><td><a href=\"http:\/\/blog.fpliu.com\/it\/software\/docker\/command\/stop\">docker stop<\/a><\/td><td>\u505c\u6b62\u6307\u5b9a\u5bb9\u5668<\/td><\/tr><tr><td><a href=\"http:\/\/blog.fpliu.com\/it\/software\/docker\/command\/ps\">docker ps<\/a><\/td><td>\u67e5\u770b\u5bb9\u5668\u7684\u72b6\u6001<\/td><\/tr><tr><td><a href=\"http:\/\/blog.fpliu.com\/it\/software\/docker\/command\/cp\">docker cp<\/a><\/td><td>\u5bb9\u5668\u548c\u5bbf\u4e3b\u4e4b\u95f4\u590d\u5236\u6587\u4ef6<\/td><\/tr><tr><td><a href=\"http:\/\/blog.fpliu.com\/it\/software\/docker\/command\/exec\">docker exec<\/a><\/td><td>\u6267\u884c\u5bb9\u5668\u4e2d\u7684\u547d\u4ee4<\/td><\/tr><tr><td><a href=\"http:\/\/blog.fpliu.com\/it\/software\/docker\/command\/attach\">docker attach<\/a><\/td><td>\u8fdb\u5165\u5bb9\u5668\u4e2d<\/td><\/tr><tr><td><a href=\"http:\/\/blog.fpliu.com\/it\/software\/docker\/command\/rm\">docker rm<\/a><\/td><td>\u5220\u9664\u6307\u5b9a\u5bb9\u5668<\/td><\/tr><tr><td><a href=\"http:\/\/blog.fpliu.com\/it\/software\/docker\/command\/inspect\">docker inspect<\/a><\/td><td>\u67e5\u770b\u6307\u5b9a\u5bb9\u5668\u7684\u8be6\u7ec6\u4fe1\u606f<\/td><\/tr><tr><td><a href=\"http:\/\/blog.fpliu.com\/it\/software\/docker\/command\/logs\">docker logs<\/a><\/td><td>\u67e5\u770b\u5bb9\u5668\u7684\u64cd\u4f5c\u65e5\u5fd7<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>1.3\u3001\u8fdb\u5165\u5bb9\u5668\u7684\u6b63\u786e\u59ff\u52bf<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u6ce8\u610f\uff1a\u6700\u597d\u4e0d\u8981\u8fdb\u5165\u5bb9\u5668\u8fdb\u884c\u64cd\u4f5c\uff0c\u5c24\u5176\u662f\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff01<\/p>\n\n\n\n<p>\u6709\u65f6\u5019\uff0c \u6211\u4eec\u53ea\u662f\u60f3\u8981\u9891\u7e41\u7684\u4f7f\u7528<a href=\"http:\/\/blog.fpliu.com\/it\/os\/Unix-like\/GNU-Linux\/distribution\/Ubuntu\">Ubuntu<\/a>\u3001<a href=\"http:\/\/blog.fpliu.com\/it\/os\/Unix-like\/GNU-Linux\/distribution\/CentOS\">CentOS<\/a>\u7b49\u5bb9\u5668\uff0c\u5e76\u4e14\u4e5f\u4e0d\u662f\u751f\u4ea7\u73af\u5883\uff0c \u90a3\u4e48\u8fdb\u5165\u5bb9\u5668\u53bb\u6267\u884c\u547d\u4ee4\u662f\u4e2a\u597d\u4e3b\u610f\uff01<\/p>\n\n\n\n<p>\u8fdb\u5165\u5bb9\u5668\u7684\u65b9\u5f0f\u4e3b\u8981\u6709\u56db\u79cd\uff1a<\/p>\n\n\n\n<ul>\n<li>\u4f7f\u7528docker exec -it &lt;containerName|containerId> \/bin\/bash<\/li>\n\n\n\n<li>\u4f7f\u7528docker attach &lt;containerName|containerId><\/li>\n\n\n\n<li>\u4f7f\u7528SSH<\/li>\n\n\n\n<li>\u4f7f\u7528nsenter<\/li>\n<\/ul>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>1.3.1\u3001docker exec<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u6267\u884c\u4e00\u4e2a\u5bb9\u5668\u91cc\u9762\u7684\u547d\u4ee4\u3002<\/p>\n\n\n\n<p><code>docker exec<\/code>\u7684\u5e2e\u52a9\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"383\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-1024x383.png\" alt=\"\" class=\"wp-image-11549\" style=\"width:511px;height:191px\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-1024x383.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-300x112.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-768x287.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-1536x574.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-830x310.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-230x86.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-350x131.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-480x179.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image.png 1814w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><code>docker exec<\/code>\u7684\u4f7f\u7528\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p><code>docker exec<\/code>\u7684\u53c2\u6570\u4e0e<code>docker run<\/code>\u7684\u53c2\u6570\u6709\u51e0\u4e2a\u662f\u76f8\u540c\u7684\u610f\u601d\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u53c2\u6570<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td>-u &lt;username|uid&gt;<\/td><td>\u6307\u5b9a\u8fdb\u5165\u7684\u5bb9\u5668\u4ee5\u54ea\u4e2a\u7528\u6237\u767b\u9646\uff0c\u9ed8\u8ba4\u662f<code>root<\/code><\/td><\/tr><tr><td>-e &lt;key=value&gt;<\/td><td>\u8bbe\u7f6e\u8fdb\u5165\u540e\u53ef\u4ee5\u4f7f\u7528\u7684\u73af\u5883\u53d8\u91cf\uff0c\u8fd9\u6837\u52a8\u6001\u6307\u5b9a\u6bd4\u8f83\u7075\u6d3b<\/td><\/tr><tr><td>-d<\/td><td>\u4ee5\u540e\u53f0\u65b9\u5f0f\u6267\u884c\uff0c\u8fd9\u6837\uff0c\u6211\u4eec\u6267\u884c\u5b8c\u8fd9\u6761\u547d\u4ee4\uff0c\u8fd8\u53ef\u4ee5\u5e72\u5176\u4ed6\u4e8b\u60c5\uff0c\u5199\u811a\u672c\u6700\u5e38\u7528<\/td><\/tr><tr><td>-i<\/td><td>\u4ee5\u4ea4\u4e92\u65b9\u5f0f\u8fd0\u884c\uff0c\u662f\u963b\u585e\u5f0f\u7684<\/td><\/tr><tr><td>-t<\/td><td>\u5206\u914d\u4e00\u4e2a\u4f2a\u7ec8\u7aef\uff0c\u8fd9\u4e2a\u53c2\u6570\u901a\u5e38\u4e0e<code>-i<\/code>\u53c2\u6570\u4e00\u8d77\u4f7f\u7528\uff0c\u7136\u540e\uff0c \u5728\u540e\u9762\u8ddf\u4e0a\u5bb9\u5668\u91cc\u7684<code>\/bin\/bash<\/code>\uff0c\u8fd9\u6837\u5c31\u628a\u6211\u4eec\u5e26\u5230\u5bb9\u5668\u91cc\u53bb\u4e86\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u793a\u4f8b1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo docker exec -u leleliu008 ubuntu ls ~<\/pre>\n\n\n\n<p>\u76f4\u63a5\u5728\u5bbf\u4e3b\u673a\u4e2d\u6267\u884c\u540d\u79f0\u4e3a<code>ubuntu<\/code>\u7684\u5bb9\u5668\u91cc\u9762\u7684<code>leleliu008<\/code>\u7528\u6237\u7684<code>ls ~<\/code>\u547d\u4ee4\uff0c \u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u8fdb\u5165\u5bb9\u5668\u540e\u518d\u51fa\u6765\u7684\u65f6\u5019\uff0c\u5f15\u8d77\u4e0d\u5fc5\u8981\u7684\u9ebb\u70e6\uff01<\/p>\n\n\n\n<p>\u793a\u4f8b2\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo docker exec -u leleliu008 -it 3dada3f22bd2 \/bin\/bash<\/pre>\n\n\n\n<p>\u8fdb\u5165<code>ubuntu<\/code>\u7684\u5bb9\u5668\u91cc\u9762\uff0c\u4ee5<code>leleliu008<\/code>\u7528\u6237\u6743\u9650\uff01<\/p>\n\n\n\n<p>\u9000\u51fa\u5bb9\u5668\u8981\u6ce8\u610f\u4e86\uff0c\u5343\u4e07\u522b\u4f7f\u7528<code>exit<\/code>\u547d\u4ee4\uff0c\u5982\u679c\u4f7f\u7528\u4e86<code>exit<\/code>\u547d\u4ee4\uff0c\u9000\u51fa\u5bb9\u5668\u7684\u540c\u65f6\u628a\u5bb9\u5668\u4e5f\u505c\u6b62\u6389\u4e86\uff0c \u8981\u60f3\u9000\u51fa\u5bb9\u5668\uff0c\u8fd8\u8ba9\u5bb9\u5668\u7ee7\u7eed\u8fd0\u884c\uff0c\u5c31\u5f97\u5148\u4f7f\u7528<code>CTRL + P<\/code>\u518d\u4f7f\u7528<code>CTRL + Q<\/code>\u5feb\u6377\u952e\uff0c \u8fd9\u6837\u5c31\u662f\u9000\u51fa\u5bb9\u5668\u4f46\u4e0d\u505c\u6b62\u5bb9\u5668\uff01<\/p>\n\n\n\n<p>\u5982\u679c\u8be5\u5bb9\u5668\u662f\u751f\u4ea7\u73af\u5883\u7684\u670d\u52a1\u5668\uff0c\u4e00\u4e0d\u5c0f\u5fc3\u4f7f\u7528\u4e86<code>exit<\/code>\u547d\u4ee4\uff0c\u628a\u5bb9\u5668\u7ed9\u505c\u6b62\u4e86\uff0c\u90a3\u5c31\u4e8b\u5927\u4e86\uff01\uff01\u6240\u4ee5\uff0c\u4e0d\u5efa\u8bae\u76f4\u63a5\u8fdb\u5165\u5bb9\u5668\u505a\u4e8b\u60c5\uff0c \u4fdd\u9669\u7684\u65b9\u6cd5\u8fd8\u662f\u5728\u5bbf\u4e3b\u673a\u5668\u4e2d\u6267\u884c\u5bb9\u5668\u91cc\u7684\u547d\u4ee4\uff01<\/p>\n\n\n\n<p>\u8fd9\u4e48\u957f\u7684\u547d\u4ee4\uff0c\u6bcf\u6b21\u90fd\u8981\u6572\u591a\u9ebb\u70e6\uff0c\u5b9e\u9645\u4e0a\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>alias<\/code>\u6765\u7ed9\u8fd9\u4e48\u957f\u7684\u547d\u4ee4\u53d6\u4e2a\u522b\u540d\uff0c \u653e\u5728\u73af\u5883\u53d8\u91cf\u91cc\u9762\uff0c\u4ee5\u540e\u5c31\u76f4\u63a5\u4f7f\u7528\u522b\u540d\u4ee3\u66ff\u90a3\u4e48\u957f\u7684\u547d\u4ee4\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">alias docker-enter-ubuntu='sudo docker exec -u leleliu008 ubuntu'<\/pre>\n\n\n\n<p>\u4ece\u8fd9\u91cc\u4e5f\u53ef\u4ee5\u770b\u51fa\uff0c\u4e3a\u4ec0\u4e48\u8981\u7ed9\u5bb9\u5668\u8d77\u4e00\u4e2a\u540d\u5b57\uff0c\u7528\u540d\u5b57\u800c\u4e0d\u662f<code>containerId<\/code>\uff0c\u5728\u670d\u52a1\u5668\u4e0a\uff0c \u4e00\u822c\u53ea\u4f1a\u4f7f\u7528\u4e00\u4e2a\u955c\u50cf\u521b\u5efa\u4e00\u4e2a\u5bb9\u5668\uff0c\u4e0d\u4f1a\u5b89\u88c5\u5f88\u591a\uff0c\u6240\u4ee5\uff0c\u7528\u540d\u5b57\u66f4\u5bb9\u6613\u5199\u811a\u672c\uff0c\u800c\u7528<code>containerId<\/code>\u6bcf\u6b21\u90fd\u8981\u4fee\u6539\u811a\u672c\uff0c\u5f88\u9ebb\u70e6\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker exec -it 8c86e41d870f \/bin\/bash\u00a0\u547d\u4ee4\u8be6\u89e3\n\ndocker exec          # \u6267\u884c\u5bb9\u5668\u5185\u547d\u4ee4\u7684Docker\u547d\u4ee4\n  -it                # \u9009\u9879\u53c2\u6570\uff08-i\uff1a\u4ea4\u4e92\u5f0f\uff0c-t\uff1a\u5206\u914d\u4f2a\u7ec8\u7aef\uff09\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000 # \u4e0d\u52a0 -it\u3000\u4f1a\u6267\u884c bash \u4f46\u65e0\u6cd5\u4ea4\u4e92\uff0c\u547d\u4ee4\u6267\u884c\u540e\u7acb\u5373\u9000\u51fa\u3002\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000 # \u52a0 -it\uff1a\u8fdb\u5165\u7c7b\u4f3c\u672c\u673a\u7ec8\u7aef\u7684\u4ea4\u4e92\u5f0f\u754c\u9762\uff0c\u663e\u793a root@container:\/# \u63d0\u793a\u7b26\u3002\n  8c86e41d870f       # \u5bb9\u5668ID\uff08\u552f\u4e00\u6807\u8bc6\u76ee\u6807\u5bb9\u5668\uff09\n  \/bin\/bash          # \u8981\u5728\u5bb9\u5668\u5185\u6267\u884c\u7684\u547d\u4ee4\uff08\u542f\u52a8Bash shell\uff09\n\n\u6838\u5fc3\u529f\u80fd\uff1a\u8fdb\u5165\u5bb9\u5668\u7684\u64cd\u4f5c\u7cfb\u7edf\u73af\u5883\uff0c\u4ee5\u4ea4\u4e92\u65b9\u5f0f\u6267\u884c\u547d\u4ee4\u3002\n\/bin\/bash \u662f\u5bb9\u5668\u5185\u7684 shell \u89e3\u91ca\u5668\uff0c\u6307\u5b9a\u5b83\u662f\u4e3a\u4e86\u83b7\u53d6\u5b8c\u6574\u7684\u4ea4\u4e92\u5f0f\u547d\u4ee4\u884c\u73af\u5883\u3002\n-it \u9009\u9879\u786e\u4fdd\u8f93\u5165\u8f93\u51fa\u4ea4\u4e92\u6b63\u5e38\uff0c\u800c\u5bb9\u5668\u955c\u50cf\u7684\u591a\u6837\u6027\uff08\u5982 Debian\/Alpine\uff09\u8981\u6c42\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684 shell \u8def\u5f84\u3002\n\u638c\u63e1\u8fd9\u4e9b\u7ec6\u8282\u540e\uff0c\u53ef\u66f4\u7075\u6d3b\u5730\u64cd\u4f5c\u5bb9\u5668\u5185\u90e8\u73af\u5883\u3002\n\n\n\u6267\u884c\u5355\u6b21\u547d\u4ee4\uff08\u5982\u67e5\u770b\u6587\u4ef6\uff09\uff1a\ndocker exec &lt;id> cat \/etc\/os-release\n\n<\/pre>\n\n\n\n<p>\u3000\u4e0d\u540c\u955c\u50cf\u7684 shell \u5dee\u5f02\u4e0e\u66ff\u4ee3\u65b9\u6848<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>\u955c\u50cf\u7c7b\u578b<\/th><th>\u9ed8\u8ba4 shell \u8def\u5f84<\/th><th>\u8fdb\u5165\u5bb9\u5668\u7684\u66ff\u4ee3\u547d\u4ee4<\/th><\/tr><\/thead><tbody><tr><td>Debian\/Ubuntu<\/td><td><code>\/bin\/bash<\/code><\/td><td><code>docker exec -it &lt;id&gt; \/bin\/bash<\/code><\/td><\/tr><tr><td>Alpine<\/td><td><code>\/bin\/sh<\/code>\uff08BusyBox\uff09<\/td><td><code>docker exec -it &lt;id&gt; \/bin\/sh<\/code><\/td><\/tr><tr><td>\u81ea\u5b9a\u4e49\u955c\u50cf<\/td><td>\u53ef\u80fd\u65e0 shell<\/td><td>\u9700\u5148\u901a\u8fc7&nbsp;<code>docker exec<\/code>&nbsp;\u6267\u884c&nbsp;<code>\/bin\/sh<\/code>&nbsp;\u6216\u5b89\u88c5&nbsp;<code>bash<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>1.3.2\u3001docker attach<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u5f53\u4e00\u4e2a\u5bb9\u5668\u4ee5\u540e\u53f0\u65b9\u5f0f\u542f\u52a8\u540e\uff0c\u6211\u4eec\u60f3\u8981\u8fdb\u5165\u8fd9\u4e2a\u5bb9\u5668\uff0c\u9664\u4e86\u4f7f\u7528<code>docker exec<\/code>\u547d\u4ee4\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u6b64\u547d\u4ee4\u3002<\/p>\n\n\n\n<p><code>docker attach<\/code>\u7684\u5e2e\u52a9\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"358\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-1-1024x358.png\" alt=\"\" class=\"wp-image-11551\" style=\"width:544px;height:189px\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-1-1024x358.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-1-300x105.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-1-768x268.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-1-1536x537.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-1-830x290.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-1-230x80.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-1-350x122.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-1-480x168.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-1.png 1814w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><code>docker attach<\/code>\u7684\u4f7f\u7528\u683c\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker attach &lt;containerName|containerId&gt;<\/pre>\n\n\n\n<p>\u793a\u4f8b1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo docker attach mysql5.7<\/pre>\n\n\n\n<p>\u793a\u4f8b2\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo docker attach 3dada3f22bd2<\/pre>\n\n\n\n<p>\u5982\u679c\u4f60\u5728\u591a\u4e2a\u7ec8\u7aef\u4e2d\u4f7f\u7528\u8fd9\u4e2a\u547d\u4ee4\u8fdb\u5165\u5bb9\u5668\uff0c\u4f60\u5728\u5176\u4e2d\u4e00\u4e2a\u7ec8\u7aef\u4e2d\u6267\u884c\u7684\u64cd\u4f5c\uff0c\u5728\u5176\u4ed6\u7ec8\u7aef\u4e2d\u662f\u540c\u6b65\u663e\u793a\u7684\uff0c \u8fd9\u5230\u5e95\u662f\u597d\u4e8b\u60c5\u8fd8\u662f\u574f\u4e8b\u60c5\uff0c\u6bcf\u4e2a\u4eba\u7684\u770b\u6cd5\u4e0d\u4e00\u6837\uff0c\u4e0d\u80fd\u4e00\u6982\u800c\u8bba\u5c31\u8bf4\u4ed6\u4e0d\u597d\uff01\u4f46\u662f\u8fd9\u4e2a\u547d\u4ee4\u7ecf\u5e38\u4f1a\u5361\u6b7b\uff0c\u5c31\u53ef\u80fd\u4e0e\u8fd9\u4e2a\u7279\u6027\u6709\u5173\u3002 \u4e00\u65e6\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u5361\u6b7b\uff0c\u4e8b\u5927\u4e86\uff01\uff01\uff01\u6240\u4ee5\u4e0d\u5efa\u8bae\u4f7f\u7528\u8fd9\u4e2a\u547d\u4ee4\uff01<\/p>\n\n\n\n<p>\u518d\u6b21\u5f3a\u8c03\uff1a\u9000\u51fa\u5bb9\u5668\u5343\u4e07\u522b\u4f7f\u7528<code>exit<\/code>\u547d\u4ee4\uff0c\u5982\u679c\u4f7f\u7528\u4e86<code>exit<\/code>\u547d\u4ee4\uff0c\u9000\u51fa\u5bb9\u5668\u7684\u540c\u65f6\u628a\u5bb9\u5668\u4e5f\u505c\u6b62\u6389\u4e86\uff0c \u8981\u60f3\u9000\u51fa\u5bb9\u5668\uff0c\u8fd8\u8ba9\u5bb9\u5668\u7ee7\u7eed\u8fd0\u884c\uff0c\u5c31\u5f97\u5148\u4f7f\u7528<code>CTRL + P<\/code>\u518d\u4f7f\u7528<code>CTRL + Q<\/code>\u5feb\u6377\u952e\uff0c \u8fd9\u6837\u5c31\u662f\u9000\u51fa\u5bb9\u5668\u4f46\u4e0d\u505c\u6b62\u5bb9\u5668\uff01<\/p>\n\n\n\n<p>\u5982\u679c\u8be5\u5bb9\u5668\u662f\u751f\u4ea7\u73af\u5883\u7684\u670d\u52a1\u5668\uff0c\u4e00\u4e0d\u5c0f\u5fc3\u4f7f\u7528\u4e86<code>exit<\/code>\u547d\u4ee4\uff0c\u628a\u5bb9\u5668\u7ed9\u505c\u6b62\u4e86\uff0c\u90a3\u5c31\u4e8b\u5927\u4e86\uff01\uff01\u6240\u4ee5\uff0c\u4e0d\u5efa\u8bae\u76f4\u63a5\u8fdb\u5165\u5bb9\u5668\u505a\u4e8b\u60c5\uff0c \u4fdd\u9669\u7684\u65b9\u6cd5\u8fd8\u662f\u5728\u5bbf\u4e3b\u673a\u5668\u4e2d\u6267\u884c\u5bb9\u5668\u91cc\u7684\u547d\u4ee4\uff01<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>1.3.3\u3001\u4f7f\u7528SSH\u8fdb\u5165\u5bb9\u5668<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u65e2\u7136<code>docker exec<\/code>\u548c<code>docker attach<\/code>\u8fdb\u5165\u5bb9\u5668\u8fd9\u4e24\u79cd\u65b9\u6cd5\u4e0d\u63a8\u8350\u4f7f\u7528\uff0c \u76f8\u4fe1\u5927\u5bb6\u7b2c\u4e00\u4e2a\u60f3\u5230\u7684\u5c31\u662f<code>SSH<\/code>\u3002\u5728\u6ca1\u6709\u4f7f\u7528<code>Docker<\/code>\u4e4b\u524d\uff0c \u6211\u4eec\u5c31\u662f\u7528<code>SSH<\/code>\u8fdb\u5165\u670d\u52a1\u5668\u8fdb\u884c\u64cd\u4f5c\u7684\u3002<\/p>\n\n\n\n<p>\u5f88\u4e0d\u5e78\uff0c\u4ecd\u7136\u662f\u4e0d\u5efa\u8bae\u4f7f\u7528<code>SSH<\/code>\u8fdb\u5165\u5230\u5bb9\u5668\u3002\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u4e0d\u5efa\u8bae\u8fd9\u4e48\u505a\uff0c\u8bf7\u53c2\u8003\u4e0b\u9762\u8fd9\u7bc7\u6587\u7ae0\uff1a<a href=\"https:\/\/blog.docker.com\/2014\/06\/why-you-dont-need-to-run-sshd-in-docker\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/blog.docker.com\/2014\/06\/why-you-dont-need-to-run-sshd-in-docker<\/a><\/p>\n\n\n\n<p>\u4e2d\u6587\u7ffb\u8bd1\u7248\u672c\uff1a<a href=\"http:\/\/www.oschina.net\/translate\/why-you-dont-need-to-run-sshd-in-docker\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/www.oschina.net\/translate\/why-you-dont-need-to-run-sshd-in-docker<\/a><\/p>\n\n\n\n<p>\u5efa\u8bae\u4f60\u770b\u539f\u6587\uff0c\u5c24\u5176\u662f\u4e0b\u9762\u7684\u5e16\u5b50\u56de\u590d\uff01\u975e\u5e38\u7cbe\u5f69\uff01<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>1.3.4\u3001\u4f7f\u7528nsenter\u8fdb\u5165\u5bb9\u5668<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p><a href=\"https:\/\/github.com\/jpetazzo\/nsenter\" target=\"_blank\" rel=\"noreferrer noopener\">\u53c2\u8003<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/blog.fpliu.com\/it\/software\/util-linux\/bin\/nsenter\">nsenter<\/a>\u662f<a href=\"http:\/\/blog.fpliu.com\/it\/software\/util-linux\">util-linux<\/a>\u4e2d\u7684\u4e00\u4e2a\u5c0f\u5de5\u5177\uff0c \u6240\u4ee5\uff0c\u8981\u4f7f\u7528\u5b83\uff0c\u5c31\u5148\u5b89\u88c5<a href=\"http:\/\/blog.fpliu.com\/it\/software\/util-linux\">util-linux<\/a>\u3002<\/p>\n\n\n\n<p>\u5b89\u88c5\u5b8c<a href=\"http:\/\/blog.fpliu.com\/it\/software\/util-linux\">util-linux<\/a>\u540e\uff0c\u6211\u4eec\u67e5\u770b<code>nsenter<\/code>\u7684\u4f7f\u7528\u5e2e\u52a9\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"613\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-2-1024x613.png\" alt=\"\" class=\"wp-image-11552\" style=\"width:461px;height:275px\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-2-1024x613.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-2-300x180.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-2-768x460.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-2-1536x920.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-2-830x497.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-2-230x138.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-2-350x210.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-2-480x287.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-2.png 1820w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><code>nsenter<\/code>\u53ef\u4ee5\u8bbf\u95ee\u53e6\u4e00\u4e2a\u8fdb\u7a0b\u7684\u540d\u79f0\u7a7a\u95f4\u3002\u800c\u5bb9\u5668\u8fd0\u884c\u8d77\u6765\u5b9e\u9645\u4e0a\u5c31\u662f\u5bbf\u4e3b\u673a\u5668\u7684\u4e00\u4e2a\u8fdb\u7a0b\u3002 \u6240\u4ee5\u4e3a\u4e86\u8fdb\u5165\u67d0\u4e2a\u5bb9\u5668\u6211\u4eec\u8fd8\u9700\u8981\u83b7\u53d6\u8be5\u5bb9\u5668\u7684\u7b2c\u4e00\u4e2a\u8fdb\u7a0b\u7684<code>PID<\/code>\u3002 \u53ef\u4ee5\u4f7f\u7528<code>docker inspect<\/code>\u547d\u4ee4\u6765\u62ff\u5230\u8be5\u4fe1\u606f\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo docker inspect -f {{.State.Pid}} ubuntu<\/pre>\n\n\n\n<p>\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528<code>nsenter<\/code>\u547d\u4ee4\u8bbf\u95ee\u8be5\u5bb9\u5668\u4e86\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nsenter --target 3326 --mount --uts --ipc --net --pid<\/pre>\n\n\n\n<p>\u8fd9\u4e48\u957f\u7684\u547d\u4ee4\u8c01\u80fd\u8bb0\u4f4f\u5462\uff1f\u5e78\u597d\u6709\u4eba\u5e2e\u6211\u4eec\u505a\u4e86\u7b80\u5316\u5de5\u4f5c\uff0c\u6211\u4eec\u53ef\u4ee5\u4e0b\u8f7d\u4e00\u4e2a<code>bash<\/code>\u811a\u672c<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/yeasy\/docker_practice\/raw\/master\/_local\/.bashrc_docker\" target=\"_blank\">.bashrc_docker<\/a>\uff0c\u628a\u5b83\u653e\u5230\u73af\u5883\u53d8\u91cf\u91cc\u9762\u5c31\u53ef\u4ee5\u4f7f\u7528\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">wget -P ~ https:\/\/github.com\/yeasy\/docker_practice\/raw\/master\/_local\/.bashrc_docker;\necho \"[ -f ~\/.bashrc_docker ] &amp;&amp; . ~\/.bashrc_docker\" &gt;&gt; ~\/.bashrc; source ~\/.bashrc<\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u5b9a\u4e49\u4e86\u5f88\u591a\u65b9\u4fbf\u4f7f\u7528<code>Docker<\/code>\u7684\u547d\u4ee4\uff0c\u4f8b\u5982<code>docker-pid<\/code>\u53ef\u4ee5\u83b7\u53d6\u67d0\u4e2a\u5bb9\u5668\u7684<code>PID<\/code>\uff1b \u800c<code>docker-enter<\/code>\u53ef\u4ee5\u8fdb\u5165\u5bb9\u5668\u6216\u76f4\u63a5\u5728\u5bb9\u5668\u5185\u6267\u884c\u547d\u4ee4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker-pid &lt;containerName|containerId&gt;\ndocker-enter &lt;containerName|containerId&gt;<\/pre>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>1.4\u3001\u5bb9\u5668\u4e4b\u95f4\u7684\u901a\u4fe1<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u4e00\u4e2a<code>Docker<\/code>\u5bb9\u5668\u5c31\u662f\u4e00\u4e2a\u5bbf\u4e3b\u673a\u4e0a\u7684\u8fdb\u7a0b\uff01\u6240\u4ee5\uff0c\u4e00\u822c\u4e00\u4e2a\u5bb9\u5668\u5c31\u662f\u4e00\u4e2a\u5e94\u7528\uff0c\u6bd4\u5982\uff0c \u6211\u4eec\u4f7f\u7528<code>nginx + Tomcat + MySQL<\/code>\u5f00\u53d1\u4e00\u4e2a<code>Java Web<\/code>\u5e94\u7528\uff0c \u6211\u4eec\u4f7f\u7528<code>Docker<\/code>\u5bb9\u5668\u5e94\u8be5\u5982\u4f55\u90e8\u7f72\u5462\uff1f<\/p>\n\n\n\n<p>\u5047\u8bbe\u6211\u4eec\u7684\u8fd9\u4e2a<code>Java Web App<\/code>\u7684\u540d\u5b57\u53eb\u505a<code>app1<\/code>\uff0c\u6240\u4ee5\uff0c\u6211\u4eec\u5728\u521b\u5efa\u5bb9\u5668\u7684\u65f6\u5019\uff0c \u7ed9\u5bb9\u5668\u547d\u540d\u7684\u65f6\u5019\uff0c\u90fd\u4ee5<code>app1<\/code>\u5f00\u5934\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u5f88\u5bb9\u5668\u770b\u51fa\u5bb9\u5668\u662f\u54ea\u4e2a<code>app<\/code>\u4f7f\u7528\u4e86\u3002<\/p>\n\n\n\n<p>\u5f53\u7136\uff0c<code>nginx<\/code>\u3001<code>Tomcat<\/code>\u3001<code>MySQL<\/code>\u8fd9\u4e9b\u8f6f\u4ef6\u90fd\u662f\u53ef\u4ee5\u88ab\u591a\u4e2a<code>app<\/code>\u540c\u65f6\u4f7f\u7528\u7684\uff0c \u4e3a\u4e86\u4fbf\u4e8e\u7ba1\u7406\uff0c\u6211\u4eec\u5c31\u4e0d\u5171\u7528\u4e86\u3002<\/p>\n\n\n\n<p>\u5047\u8bbe\u6211\u4eec\u8fd9\u91cc\u7684<code>nginx<\/code>\u505a\u8d1f\u8f7d\u5747\u8861\u4f7f\u7528\uff0c<code>MySQL<\/code>\u4f7f\u7528\u4e86\u4e3b\u4ece\u590d\u5236\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u662f<code>app1<\/code>\u7684\u67b6\u6784\u56fe\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"637\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-3-1024x637.png\" alt=\"\" class=\"wp-image-11553\" style=\"width:594px;height:369px\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-3-1024x637.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-3-300x187.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-3-768x478.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-3-1536x956.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-3-830x516.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-3-230x143.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-3-350x218.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-3-480x299.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-3.png 2006w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u6211\u4eec\u9700\u8981\u521b\u5efa5\u4e2a<code>Docker<\/code>\u5bb9\u5668\uff1a<\/p>\n\n\n\n<p><code>app1-mysql-master<\/code>\u7528\u4f5c<code>MySQL<\/code>\u4e3b\u670d\u52a1\u5668\u3002<\/p>\n\n\n\n<p><code>app1-mysql-slave<\/code>\u7528\u4f5c<code>MySQL<\/code>\u4ece\u670d\u52a1\u5668\u3002<\/p>\n\n\n\n<p><code>app1-tomcat-load-1<\/code>\u662f\u7b2c\u4e00\u4e2a\u8d1f\u8f7d\u3002\u5b83\u80af\u80fd\u8bbf\u95ee<code>app1-mysql-master<\/code>\u5bb9\u5668\uff0c \u4e5f\u53ef\u80fd\u8bbf\u95ee<code>app1-mysql-slave<\/code>\u5bb9\u5668\u3002<\/p>\n\n\n\n<p><code>app1-tomcat-load-2<\/code>\u662f\u7b2c\u4e8c\u4e2a\u8d1f\u8f7d\u3002\u5b83\u80af\u80fd\u8bbf\u95ee<code>app1-mysql-master<\/code>\u5bb9\u5668\uff0c \u4e5f\u53ef\u80fd\u8bbf\u95ee<code>app1-mysql-slave<\/code>\u5bb9\u5668\u3002<\/p>\n\n\n\n<p><code>app1-nginx<\/code>\u662f\u8d1f\u8f7d\u5747\u8861\u8c03\u5ea6\u5668\u3002 \u5b83\u53ea\u8bbf\u95ee<code>app1-tomcat-load-1<\/code>\u548c<code>app1-tomcat-load-2<\/code>\u8fd9\u4e24\u4e2a\u5bb9\u5668\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>1.4.1\u3001link\u673a\u5236\u5b9e\u73b0\u5bb9\u5668\u4e4b\u95f4\u7684\u901a\u4fe1<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p><a href=\"https:\/\/docs.docker.com\/engine\/userguide\/networking\/default_network\/dockerlinks\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u53c2\u8003\u6587\u6863<\/a><\/p>\n\n\n\n<p>\u5f88\u4e0d\u5e78\uff0c\u8fd9\u79cd\u65b9\u5f0f\u5df2\u7ecf\u4e0d\u5efa\u8bae\u4f7f\u7528\u4e86\uff0c\u88ab\u66f4\u597d\u7684\u65b9\u6cd5\u53d6\u4ee3\u4e86\u3002\u5b98\u65b9\u4e3a\u4e86\u517c\u5bb9\u8001\u7248\u672c\uff0c \u8fd9\u4e2a\u7279\u6027\u4ecd\u7136\u4fdd\u7559\u4e86\uff0c\u4f46\u662f\u5f88\u53ef\u80fd\u5728\u4ee5\u540e\u7684\u67d0\u4e2a\u7248\u672c\u88ab\u5f7b\u5e95\u5e9f\u5f03\uff01<\/p>\n\n\n\n<p><code>link<\/code>\u539f\u7406\u56fe\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"376\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-4-1024x376.png\" alt=\"\" class=\"wp-image-11554\" style=\"width:567px;height:208px\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-4-1024x376.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-4-300x110.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-4-768x282.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-4-1536x564.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-4-830x305.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-4-230x84.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-4-350x129.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-4-480x176.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/07\/image-4.png 2036w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u8981<code>link<\/code>\u7684\u5bb9\u5668\u88ab\u79f0\u4e3a<code>received-container<\/code>\u3002<\/p>\n\n\n\n<p>\u88ab<code>link<\/code>\u7684\u5bb9\u5668\u88ab\u79f0\u4e3a<code>source-container<\/code>\u3002<\/p>\n\n\n\n<p><code>received-container<\/code>\u5bb9\u5668\u53ef\u4ee5\u8bbf\u95ee<code>source-container<\/code>\u5bb9\u5668\u3002<\/p>\n\n\n\n<p>\u5b9e\u73b0\u65b9\u5f0f\u662f\u901a\u8fc7<code>docker run<\/code>\u547d\u4ee4\u7684<code>--link &lt;source-containerName|source-containerId:source-containerAlias&gt;<\/code>\u53c2\u6570\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u4f7f\u7528<code>link<\/code>\u673a\u5236\u5b9e\u73b0\u4e00\u4e0b\u8fd9\u4e2a\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<p>1\u3001\u521b\u5efa<code>app1-mysql-master<\/code>\u5bb9\u5668\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo docker run -d -p 3306:3306 -v ~\/app1\/mysql\/data\/master:\/usr\/local\/mysql\/data --name app1-mysql-master mysql:5.6<\/pre>\n\n\n\n<p>2\u3001\u521b\u5efa<code>app1-mysql-slave<\/code>\u5bb9\u5668\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo docker run -d -p 3307:3306 -v ~\/app1\/mysql\/data\/slave:\/usr\/local\/mysql\/data --name app1-mysql-slave mysql:5.6<\/pre>\n\n\n\n<p>3\u3001\u521b\u5efa<code>app1-tomcat-load-1<\/code>\u5bb9\u5668\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo docker run -d -p 8080:8080 -v ~\/app1\/tomcat\/load-1\/log:\/usr\/local\/tomcat\/log --name app1-tomcat-load-1 --link app1-mysql-master:app1-mysql-master --link app1-mysql-slave:app1-mysql-slave tomcat:8<\/pre>\n\n\n\n<p>4\u3001\u521b\u5efa<code>app1-tomcat-load-2<\/code>\u5bb9\u5668\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo docker run -d -p 8081:8080 -v ~\/app1\/tomcat\/load-2\/log:\/usr\/local\/tomcat\/log --name app1-tomcat-load-2 --link app1-mysql-master:app1-mysql-master --link app1-mysql-slave:app1-mysql-slave tomcat:8<\/pre>\n\n\n\n<p>5\u3001\u521b\u5efa<code>app1-nginx<\/code>\u5bb9\u5668\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo docker run -d -p 80:80 -v ~\/app1\/nginx\/conf:\/usr\/local\/nginx\/conf --name app1-nginx --link app1-tomcat-load-1:app1-tomcat-load-1 --link app1-tomcat-load-2:app1-tomcat-load-2 nginx:1.11<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1.1\u3001Docker\u5bb9\u5668\u662f\u4ec0\u4e48 Docker\u5bb9\u5668\u8fd0\u884c\u8d77\u6765\u672c\u8d28\u4e0a\u5c31\u662f\u5bbf\u4e3b\u673a\u91cc\u9762\u7684\u4e00\u4e2a\u8fdb\u7a0b\u3002 \u3000 1.2\u3001\u5bb9\u5668\u7684\u76f8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11547"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11547"}],"version-history":[{"count":5,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11547\/revisions"}],"predecessor-version":[{"id":18148,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11547\/revisions\/18148"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}