{"id":8703,"date":"2024-04-29T12:01:01","date_gmt":"2024-04-29T04:01:01","guid":{"rendered":""},"modified":"2024-04-29T12:01:01","modified_gmt":"2024-04-29T04:01:01","slug":"docker\u5bb9\u5668\u5185\u7684attached \u548cdetached\u6a21\u5f0f","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8703.html","title":{"rendered":"docker\u5bb9\u5668\u5185\u7684attached \u548cdetached\u6a21\u5f0f"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u535a\u4e3b\u4ecb\u7ecd<\/font><\/h2>\n

\ud83d\udce2\u70b9\u51fb\u4e0b\u5217\u5185\u5bb9\u53ef\u8df3\u8f6c\u5bf9\u5e94\u7684\u754c\u9762\uff0c\u67e5\u770b\u66f4\u591a\u7cbe\u5f69\u5185\u5bb9\uff01<\/font><\/i><\/font><\/p>\n

\n

\ud83c\udf4e\u4e3b\u9875\uff1a<\/b><\/font>\u6c34\u9999\u6728\u9c7c<\/b><\/font>
\ud83c\udf4d\u4e13\u680f\uff1a<\/b><\/font>docker<\/b><\/font><\/p>\n<\/blockquote>\n


\n

\u6587\u7ae0\u76ee\u5f55<\/font><\/h2>\n
\n

\u7b80\u4ecb\uff1a\u8fd9\u662f\u4e00\u7bc7\u6709\u5173\u3010docker\u5bb9\u5668\u5185\u7684attached \u548cdetached\u6a21\u5f0f\u3011<\/font>\u7684\u6587\u7ae0\uff0c\u535a\u4e3b\u7528\u6700\u7cbe\u7b80\u7684\u8bed\u8a00<\/code>\u53bb\u8868\u8fbe\u7ed9\u524d\u7aef\u8bfb\u8005\u4eec\u3002<\/p>\n<\/blockquote>\n

\n <\/p>\n

\n \n <\/g> \n \n \n <\/path> \n \n \n <\/path> \n <\/marker> \n <\/defs> \n <\/g> \n \n <\/path> \n \n \n <\/path> \n <\/marker> \n <\/defs> \n <\/g> \n \n <\/path> \n \n \n <\/path> \n <\/marker> \n <\/defs> \n <\/g> \n <\/g> \n \n \n \n <\/rect> \n <\/p>\n

\n <\/span> \n <\/div>\n

<\/foreignobject> \n <\/g> \n <\/g> \n \n \n <\/rect> \n <\/p>\n

\n <\/span> \n <\/div>\n

<\/foreignobject> \n <\/g> \n <\/g> \n \n \n <\/rect> \n <\/p>\n

\n <\/span> \n <\/div>\n

<\/foreignobject> \n <\/g> \n <\/g> \n <\/g> \n \n \n <\/rect> \n \n \n <\/p>\n

\n \u7aef\u53e3\u6620\u5c04 \n <\/div>\n

<\/foreignobject> \n <\/g> \n <\/g> \n <\/g> \n \n <\/rect> \n \n \n <\/p>\n

\n attached\u6a21\u5f0f \n <\/div>\n

<\/foreignobject> \n <\/g> \n <\/g> \n <\/g> \n \n <\/rect> \n \n \n <\/p>\n

\n detached\u6a21\u5f0f \n <\/div>\n

<\/foreignobject> \n <\/g> \n <\/g> \n <\/g> \n \n <\/rect> \n \n \n <\/p>\n

\n detached\u6a21\u5f0f\u8f6c\u6362attached\u6a21\u5f0f \n <\/div>\n

<\/foreignobject> \n <\/g> \n <\/g> \n <\/g> \n <\/g> \n <\/g> \n <\/g> \n <\/svg>\n<\/div>\n

1\u3001Docker\u7aef\u53e3\u6620\u5c04<\/font><\/h3>\n
\n

\u5728\u5f00\u542f\u7aef\u53e3\u6620\u5c04\u4e4b\u524d\uff0c\u4f60\u9996\u5148\u8981\u4e4b\u9053Docker\u5bf9\u5e94\u7684\u5bb9\u5668\u7aef\u53e3<\/code>\u662f\u591a\u5c11\u3002\u6bd4\u5982Nginx\u955c\u50cf\u7684\u7aef\u53e3\u8bd780\u3002<\/p>\n<\/blockquote>\n

\u77e5\u9053\u8fd9\u4e2a\u7aef\u53e3\u540e\uff0c\u5c31\u53ef\u4ee5\u5728\u542f\u52a8\u5bb9\u5668\u7684\u65f6\u5019\uff0c\u7528-p <port:port><\/code> \u7684\u5f62\u5f0f\uff0c\u542f\u7528\u6620\u5c04\u4e86\u3002<\/p>\n

\u7528Nginx\u4e3e\u4f8b:<\/p>\n

docker container run -p 80:80 nginx\n<\/code><\/pre>\n

\u7b49\u5f85\u9879\u76ee\u542f\u52a8\u540e\uff0c\u6253\u5f00\u6d4f\u89c8\u5668\u7a97\u53e3\uff0c\u5728\u5730\u5740\u680f\u8f93\u5165127.0.0.1<\/code>\uff0c\u5c31\u53ef\u4ee5\u6253\u5f00nginx\u7684\u9ed8\u8ba4\u7f51\u5740\u3002<\/p>\n

\"docker\u5bb9\u5668\u5185\u7684attached<\/p>\n

    \n
  • \u7b2c\u4e00\u4e2a\u7aef\u53e3\u662f\u6620\u5c04\u5230\u670d\u52a1\u5668\u672c\u673a\u7684\u7aef\u53e3<\/code>;<\/li>\n
  • \u7b2c\u4e8c\u4e2a\u7aef\u53e3\u662fDocker\u5bb9\u5668\u4f7f\u7528\u7684\u7aef\u53e3<\/code>\u3002<\/li>\n<\/ul>\n

    \u6bd4\u5982\u4f60\u60f3\u628aDocker\u768480\u7aef\u53e3\uff0c\u6620\u5c04\u5230\u670d\u52a1\u5668\u768490\u7aef\u53e3<\/code>,\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n

    docker container run -p 90:80 nginx\n<\/code><\/pre>\n

    2\u3001attached\u6a21\u5f0f<\/font><\/h3>\n

    \u4e24\u79cd\u6a21\u5f0f\u6700\u7b80\u5355\u7684\u5bf9\u6bd4\u7406\u89e3\u5c31\u662f\uff1aattached\u6a21\u5f0f\u5728\u524d\u53f0\u8fd0\u884c\uff0cdetached\u6a21\u5f0f\u5728\u540e\u53f0\u8fd0\u884c\u3002<\/p>\n

    \u5f53\u4f60\u6253\u5f00127.0.0.1<\/code>\u7f51\u5740\u7684\u65f6\u5019\uff0cPowerShell<\/code>\u4e0a\u6253\u5370\u51fa\u4e86\u76f8\u5173\u7684\u65e5\u5fd7\uff08log\uff09\uff0c\u5e73\u4e14\u6bcf\u8bbf\u95ee\u4e00\u6b21\uff0c\u90fd\u4f1a\u589e\u52a0\u4e00\u6761\u65e5\u5fd7\u3002<\/p>\n

    \u4e5f\u5c31\u662f\u8bf4Docker\u5bb9\u5668\u7684\u65e5\u5fd7\u4f1a\u5b9e\u65f6\u7684\u5c55\u73b0\u5230\u7a97\u53e3\u5e76\u4e14\u5360\u7528\u6b64\u7aef\u53e3\u3002\u8fd9\u79cd\u6a21\u5f0f\u53eb\u505aattached\u6a21\u5f0f<\/code><\/p>\n

    \"docker\u5bb9\u5668\u5185\u7684attached<\/p>\n

    \n

    \u5728windows\u7cfb\u7edf\u4e0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u5b8c\u6574\u7684attached\u6a21\u5f0f\uff0c\u53ea\u662f\u5e2e\u6211\u4eec\u6253\u5370\u51fa\u4e86Log\u3002<\/p>\n<\/blockquote>\n

    \n

    \u73b0\u5728\u5230Linux\u670d\u52a1\u5668\u4e0a\uff0c\u8fd9\u65f6\u5019\u4f60\u6309Ctrl+C,\u5c31\u4f1a\u505c\u6b62\u6389Docker\u670d\u52a1<\/code>\u3002\u800c\u73b0\u5b9e\u4e2d\u6211\u4eec\u5de5\u4f5c\u7684\u73af\u5883\u6070\u6070\u662f\u8fd9\u79cdLinux\u73af\u5883\u3002<\/p>\n<\/blockquote>\n

    \u3010\u4e5f\u5c31\u662f\u5728Linux\u4e0a\u4f60\u7684\u64cd\u4f5c\u547d\u4ee4\uff0c\u4f1a\u76f4\u63a5\u4f20\u9012\u4e2aDocker\u5bb9\u5668\u3002\u8fd9\u4e2a\u7f3a\u70b9\u5c31\u662f\u5f88\u5bb9\u6613\u8bef\u64cd\u4f5c\uff0c\u6bd4\u5982\u5728\u516c\u53f8\u7684\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u4f60\u76f4\u63a5\u4e00\u4e2aCtrl+C\uff0c\u6574\u4e2a\u670d\u52a1\u5c31\u5d29\u6389\u4e86\uff0c\u4f60\u8fd9\u4e2a\u6708\u7684\u7ee9\u6548\u4e5f\u5c31\u6ca1\u6709\u4e86\u3002\u3011<\/font><\/p>\n

    \u6240\u4ee5\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u66f4\u597d\u7684\uff0c\u66f4\u7a33\u5b9a\u7684\u6a21\u5f0f\u3002\u4e5f\u5c31\u662fdetached\u6a21\u5f0f<\/code>\u3002<\/p>\n

    \u6ce8\u610f\uff1aattached\u6a21\u5f0f\u66f4\u9002\u7528\u4e8e\u5bb9\u5668\u548c\u7a0b\u5e8f\u7684\u8c03\u8bd5\u9636\u6bb5<\/code><\/p>\n

    3\u3001detached\u6a21\u5f0f<\/font><\/h3>\n
    \n

    detached\u6a21\u5f0f\u7684\u5f00\u542f\u65b9\u6cd5\uff0c\u5c31\u662f\u52a0\u4e00\u4e2a\u53c2\u6570-d<\/code>\u6216\u8005--detach<\/code><\/p>\n<\/blockquote>\n

    docker run -d -p 80:80 nginx\n<\/code><\/pre>\n

    \u8fd9\u6b21\u4f60\u4f1a\u770b\u5230\uff0c\u548cattached\u6a21\u5f0f\u4e0d\u540c\u7684\u662f\uff0c\u8fd9\u6b21\u8f93\u5165\u5b8c\u547d\u4ee4\u540e\uff0c\u53ea\u663e\u793a\u51fa\u4e86\u5bb9\u5668\u7684\u7f16\u53f7<\/code>\uff0c\u5e76\u4e14\u53ef\u4ee5\u518d\u8f93\u5165\u4efb\u4f55\u547d\u4ee4<\/code>\u3002<\/p>\n

    \u5c31\u7b97\u6211\u4eec\u5173\u6389\u7a97\u53e3\uff0c\u5bb9\u5668\u4f9d\u7136\u8fd0\u884c\uff0c\u4e5f\u5c31\u662f\u4ed6\u662f\u5728\u7cfb\u7edf\u540e\u53f0\u8fdb\u884c\u8fd0\u884c\u7684\u3002<\/p>\n

    \u8fd9\u79cd\u5c31\u6bd4\u8f83\u9002\u5408\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u8fd0\u884c\uff0c\u505c\u6389\u548c\u5220\u9664\u5bb9\u5668\u90fd\u9700\u8981\u4f7f\u7528Shell\u811a\u672c\u7684\u5f62\u5f0f\u3002\u51cf\u5c11\u4e86\u5f88\u591a\u8bef\u64cd\u4f5c\u3002<\/code><\/p>\n

    4\u3001detached\u6a21\u5f0f\u8f6c\u6362attached\u6a21\u5f0f<\/font><\/h3>\n

    \u5728\u8fd0\u884c\u4e4b\u540e\uff0c\u4e5f\u6709\u9700\u8981\u8c03\u8bd5\u7684\u65f6\u5019\uff0cDocker\u63d0\u4f9b\u4e86\u4e24\u4e2a\u6a21\u5f0f\u95f4\u7684\u8f6c\u6362\u3002<\/p>\n

    \u6bd4\u5982\u73b0\u5728\u8981\u628adetached\u6a21\u5f0f\u7684\u5bb9\u5668\uff0c\u6539\u4e3aattched\u6a21\u5f0f<\/code><\/p>\n

    docker  attach <ID or Image Name>\n<\/code><\/pre>\n
    \n

    \u76f8\u5173\u63a8\u8350<\/font><\/h2>\n
    \n

    \u2b50doker\u7684\u591a\u5bb9\u5668\u64cd\u4f5c\u548c\u5f3a\u5236\u5220\u9664\u5bb9\u5668\u7684\u65b9\u6cd5
    \u2b50docker\u521b\u5efa\u5bb9\u5668\u76f8\u5173\u547d\u4ee4\u3010\u8be6\u7ec6\u7248\u3011
    \u2b50\u5982\u4f55\u5728Linux\u7cfb\u7edf\u4e0b\u5b89\u88c5Docker
    \u2b50\u5982\u4f55\u5b89\u88c5Docker\u684c\u9762\u7248\u5230Windows\u7cfb\u7edf\u4e0a
    \u2b50\u5728Windows10\u3001Windows11\u7cfb\u7edf\u4e0b\u5b89\u88c5Docker<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"docker\u5bb9\u5668\u5185\u7684attached \u548cdetached\u6a21\u5f0fdocker\u5bb9\u5668\u5185\u7684attached\u548cdetached\u6a21\u5f0f_dockerdetach","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8703"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=8703"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8703\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}