{"id":2912,"date":"2019-02-28T23:34:41","date_gmt":"2019-02-28T15:34:41","guid":{"rendered":"https:\/\/damogame.cn:15443\/wordpress\/?p=2912"},"modified":"2019-02-28T23:34:41","modified_gmt":"2019-02-28T15:34:41","slug":"docker%e6%96%b0%e6%89%8b%e5%85%a5%e9%97%a8%e4%b9%8b%e5%9b%9b%ef%bc%9adocker%e9%95%9c%e5%83%8f%e5%92%8c%e4%bb%93%e5%ba%93%e7%9a%84%e5%9f%ba%e6%9c%ac%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/2912","title":{"rendered":"Docker\u65b0\u624b\u5165\u95e8\u4e4b\u56db\uff1aDocker\u955c\u50cf\u548c\u4ed3\u5e93\u7684\u57fa\u672c\u4f7f\u7528"},"content":{"rendered":"<div class=\"article-title\"><\/div>\n<div class=\"article-desc clearfix\">\n<div class=\"author-txt\">\n<div class=\"article-source article-source-bjh\">\u5728\u4e4b\u524d\u7684\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u8bb2\u89e3\u4e86\u4ec0\u4e48\u662fDocker\uff0c\u4ee5\u53ca\u5982\u4f55\u8fd0\u884cDocker\u5bb9\u5668\u3002<\/div>\n<\/div>\n<\/div>\n<div class=\"article-content\">\n<p><span class=\"bjh-p\">\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8981\u7ee7\u7eed\u8bb2\u89e3Docker\u955c\u50cf\u7684\u76f8\u5173\u6982\u5ff5\u4e0e\u64cd\u4f5c\u3002<\/span><\/p>\n<p><span class=\"bjh-p\">Docker\u955c\u50cf\u662f\u542f\u52a8\u5bb9\u5668\u7684\u57fa\u77f3\u3002<\/span><\/p>\n<p><span class=\"bjh-p\">\u672c\u6587\u4e2d\u5c06\u4f1a\u8bb2\u89e3\u5982\u4f55\u7ba1\u7406\u3001\u4fee\u6539\u955c\u50cf\u4ee5\u53ca\u955c\u50cf\u5b58\u50a8\u4ed3\u5e93Registry\u7684\u76f8\u5173\u77e5\u8bc6\u3002<\/span><\/p>\n<p><span class=\"bjh-h3\">\u4ec0\u4e48\u662fDocker\u955c\u50cf<\/span><\/p>\n<p>Docker\u955c\u50cf\u662f\u7531\u6587\u4ef6\u7cfb\u7edf\u53e0\u52a0\u800c\u6210\u3002\u6700\u5e95\u7aef\u662f\u4e00\u4e2a\u6587\u4ef6\u5f15\u5bfc\u7cfb\u7edf\uff0c\u5373bootfs\u3002Docker\u7528\u6237\u4e0d\u4f1a\u4e0e\u5f15\u5bfc\u6587\u4ef6\u7cfb\u7edf\u6709\u76f4\u63a5\u7684\u4ea4\u4e92\u3002Docker\u955c\u50cf\u7684\u7b2c\u4e8c\u5c42\u662froot\u6587\u4ef6\u7cfb\u7edfrootfs\uff0c\u901a\u5e38\u662f\u4e00\u79cd\u6216\u591a\u79cd\u64cd\u4f5c\u7cfb\u7edf\uff0c\u4f8b\u5982ubuntu\u7b49\u3002\u5728Docker\u4e2d\uff0c\u6587\u4ef6\u7cfb\u7edf\u6c38\u8fdc\u90fd\u662f\u53ea\u8bfb\u7684\uff0c\u5728\u6bcf\u6b21\u4fee\u6539\u65f6\uff0c\u90fd\u662f\u8fdb\u884c\u62f7\u8d1d\u53e0\u52a0\u4ece\u800c\u5f62\u6210\u6700\u7ec8\u7684\u6587\u4ef6\u7cfb\u7edf\u3002Docker\u79f0\u8fd9\u6837\u7684\u6587\u4ef6\u4e3a\u955c\u50cf\u3002\u4e00\u4e2a\u955c\u50cf\u53ef\u4ee5\u8fed\u4ee3\u5728\u53e6\u4e00\u4e2a\u955c\u50cf\u7684\u9876\u90e8\u3002\u4f4d\u4e8e\u4e0b\u65b9\u7684\u955c\u50cf\u79f0\u4e4b\u4e3a\u7236\u955c\u50cf\uff0c\u6700\u5e95\u5c42\u7684\u955c\u50cf\u79f0\u4e4b\u4e3a<span class=\"bjh-strong\">\u57fa\u7840\u955c\u50cf<\/span>\u3002\u6700\u540e\uff0c\u5f53\u4ece\u4e00\u4e2a\u955c\u50cf\u542f\u52a8\u5bb9\u5668\u65f6\uff0cDocker\u4f1a\u5728\u6700\u9876\u5c42\u52a0\u8f7d\u4e00\u4e2a\u8bfb\u5199\u6587\u4ef6\u7cfb\u7edf\u4f5c\u4e3a\u5bb9\u5668\u3002<\/p>\n<div class=\"img-container\"><img decoding=\"async\" class=\"normal\" src=\"https:\/\/ss0.baidu.com\/6ONWsjip0QIZ8tyhnq\/it\/u=3369975786,3119282502&amp;fm=173&amp;s=1EAA7423425843CA0CF9E0D60100E0A1&amp;w=265&amp;h=334&amp;img.JPEG\" width=\"265px\" data-loadfunc=\"0\" data-loaded=\"0\" \/><\/div>\n<p>Docker\u7684\u8fd9\u79cd\u673a\u5236\u6211\u4eec\u79f0\u4e4b\u4e3a<span class=\"bjh-strong\">\u5199\u65f6\u590d\u5236<\/span>\u3002<\/p>\n<p><span class=\"bjh-h3\">\u67e5\u770b\u955c\u50cf\u5217\u8868<\/span><\/p>\n<p><span class=\"bjh-p\">\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4e86\u89e3\u4e00\u4e0b\u5173\u4e8e\u955c\u50cf\u76f8\u5173\u7684\u4e00\u4e9b\u64cd\u4f5c\u3002\u9996\u5148\u662f\u67e5\u8be2\u955c\u50cf\u5217\u8868\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">sudo docker images<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u8be5\u547d\u4ee4\u53ef\u4ee5\u7528\u4e8e\u67e5\u627e\u5f53\u524d\u7cfb\u7edf\u4e2d\u6240\u6709\u5b58\u5728\u7684\u955c\u50cf\u5217\u8868\u3002Ps\uff1a\u672c\u5730\u955c\u50cf\u9ed8\u8ba4\u4fdd\u5b58\u5728Docker\u5bbf\u4e3b\u673a\u7684\/var\/lib\/docker\u76ee\u5f55\u4e0b\u3002\u6240\u6709\u7684\u955c\u50cf\u90fd\u662f\u4fdd\u5b58\u5728\u4ed3\u5e93\u4e2d\uff0c\u800c\u4ed3\u5e93\u4f4d\u4e8eRegistry\u4e2d\u3002\u9ed8\u8ba4\u7684Registry\u662fDocker\u516c\u53f8\u8fd0\u8425\u7684Docker Hub\u3002\u6bcf\u4e2a\u955c\u50cf\u4ed3\u5e93\u90fd\u53ef\u4ee5\u5b58\u653e\u5f88\u591a\u7684\u955c\u50cf\u3002\u4f8b\u5982ubuntu\u955c\u50cf\u4ed3\u5e93\u5b58\u653e\u7740\u5404\u79cd\u4e0d\u540c\u7248\u672c\u7684Ubuntu\u955c\u50cf\u3002\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u53ef\u4ee5\u62c9\u53d6\u955c\u50cf\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">sudo docker pull ubuntu<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u4e0a\u8ff0\u547d\u4ee4\u4f1a\u62c9\u53d6\u6240\u6709\u7248\u672c\u7684ubuntu\u955c\u50cf\u5230\u672c\u5730\u3002\u4e3a\u4e86\u533a\u5206\u540c\u4e00\u4e2a\u4ed3\u5e93\u4e2d\u4e0d\u540c\u7684\u955c\u50cf\uff0cDocker\u63d0\u4f9b\u4e86\u4e00\u79cdtag\u7684\u529f\u80fd\u3002\u6211\u4eec\u53ef\u4ee5\u7ed9\u6bcf\u4e2a\u7248\u672c\u7684\u955c\u50cf\u6dfb\u52a0\u4e00\u4e2a\u552f\u4e00\u7684tag\u6765\u6807\u8bc6\u8be5\u955c\u50cf\u3002\u6b64\u65f6\uff0c\u955c\u50cf\u7684\u540d\u79f0\u5982\u4e0b\uff1a\u4ed3\u5e93\u540d\u79f0:tag\u3002\u6211\u4eec\u5728\u8fd0\u884c\u955c\u50cf\u6216\u62c9\u53d6\u955c\u50cf\u65f6\uff0c\u53ef\u4ee5\u76f4\u63a5\u6307\u5b9a\u5bf9\u5e94\u7684\u6807\u7b7e\u3002\u4f8b\u5982\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">sudo docker run -it ubuntu:16.04 \/bin\/bash<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5728run\u4e2d\u5982\u679c\u6ca1\u6709\u6307\u5b9a\u955c\u50cf\u7684tag\uff0c\u5c06\u4f1a\u9ed8\u8ba4\u53bb\u5bfb\u627elatest\u6807\u7b7e\u7684\u955c\u50cf\u3002\u9664\u4e86\u4ed3\u5e93\u540d\u79f0\u548ctag\u4ee5\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u5c06\u955c\u50cf\u5206\u4e3a\u4e24\u4e2a\u7c7b\u522b\uff1a\u4e00\u79cd\u662fDocker\u7528\u6237\u81ea\u5df1\u521b\u5efa\u7684\u7528\u6237\u4ed3\u5e93\uff0c\u8fd8\u6709\u4e00\u79cd\u662fDocker\u5b98\u65b9\u7ef4\u62a4\u7684\u9876\u5c42\u4ed3\u5e93\u3002\u7528\u4e8e\u4ed3\u5e93\u7684\u5b8c\u6574\u540d\u79f0\u662f\u7531\u7528\u6237\u540d\u79f0\/\u4ed3\u5e93\u540d\u79f0\u7ec4\u6210\u7684\u3002\u800c\u5bf9\u4e8e\u9876\u5c42\u4ed3\u5e93\u800c\u8a00\uff0c\u5219\u6ca1\u6709\u7528\u6237\u540d\u79f0\uff0c\u76f4\u63a5\u662f\u4ed3\u5e93\u540d\u79f0\u3002\u603b\u7ed3\u4e00\u4e0b\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u4ed3\u5e93\u800c\u8a00\uff0c\u5b8c\u6210\u7684\u683c\u5f0f\u5982\u4e0b\uff1a[\u7528\u6237\u540d\u79f0\/]\u4ed3\u5e93\u540d\u79f0:tag\u3002<\/span><\/p>\n<p><span class=\"bjh-h3\">\u62c9\u53d6\u955c\u50cf<\/span><\/p>\n<p><span class=\"bjh-p\">\u5728\u4f7f\u7528docker run\u4ece\u4e00\u4e2a\u955c\u50cf\u542f\u52a8\u5bb9\u5668\u65f6\uff0cDocker\u9996\u5148\u4f1a\u73b0\u5728\u672c\u5730\u67e5\u627e\u662f\u5426\u5b58\u5728\u8be5\u955c\u50cf\u3002\u5982\u679c\u5728\u672c\u5730\u6ca1\u6709\u627e\u5230\u8be5\u955c\u50cf\uff0c\u5219\u4f1a\u5148\u4eceDockers Hub\u4e0a\u4e0b\u8f7d\u8be5\u955c\u50cf\u540e\u5728\u8fd0\u884c\u3002Ps\uff1a\u5982\u4e4b\u524d\u6240\u8bf4\uff0c\u5982\u679c\u6ca1\u6709\u6307\u5b9atag\uff0c\u5219\u9ed8\u8ba4\u4f7f\u7528latest\u6807\u7b7e\u3002<\/span><\/p>\n<p><span class=\"bjh-h3\">\u67e5\u627e\u955c\u50cf<\/span><\/p>\n<p><span class=\"bjh-p\">\u6211\u4eec\u5982\u679c\u60f3\u8981\u4eceDocker Hub\u67e5\u627e\u6709\u54ea\u4e9b\u516c\u5171\u7684\u53ef\u7528\u955c\u50cf\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">sudo docker search keywords<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-h3\">\u6784\u5efa\u955c\u50cf<\/span><\/p>\n<p><span class=\"bjh-p\">\u5728\u4e0a\u9762\u7684\u5185\u5bb9\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u4e86\u89e3\u4e86\u5982\u4e0b\u67e5\u8be2\uff0c\u62c9\u53d6\uff0c\u8fd0\u884c\u955c\u50cf\uff0c\u90a3\u4e48\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u4f1a\u7ee7\u7eed\u5b66\u4e60\u5982\u4f55\u4fee\u6539\u3001\u66f4\u65b0\u548c\u7ba1\u7406\u81ea\u5df1\u7684\u955c\u50cf\u3002\u6784\u5efa\u955c\u50cf\u7684\u65b9\u5f0f\u6709\u4ee5\u4e0b\u4e24\u79cd\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">\u4f7f\u7528docker commit\u6784\u5efa<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">\u4f7f\u7528docker build\u548cDockerfile\u6587\u4ef6\u6765\u6784\u5efa<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u76f8\u6bd4\u8f83\u800c\u8a00\uff0c\u6211\u4eec\u66f4\u52a0\u63a8\u8350\u4f7f\u7528\u65b9\u6cd52\u6765\u6784\u5efa\u3002\u56e0\u4e3a\u65b9\u6cd52\u66f4\u52a0\u7684\u7075\u6d3b\u548c\u5f3a\u5927\u3002Ps\uff1a\u6211\u4eec\u901a\u5e38\u5e76\u4e0d\u662f\u4ece\u96f6\u5f00\u59cb\u6784\u5efa\u4e00\u4e2a\u955c\u50cf\uff0c\u800c\u662f\u4ece\u4e00\u4e2abase\u955c\u50cf\u5f00\u59cb\u4fee\u6539\u6784\u5efa\u7684\u3002\u5728\u63a5\u4e0b\u6765\u7684\u5185\u5bb9\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5c06\u4f1a\u7b80\u5355\u7684\u8bb2\u89e3\u4e00\u4e0b\u5982\u4f55\u901a\u8fc7docker commit\u6765\u4fee\u6539\u955c\u50cf\u3002\u4f46\u66f4\u591a\u7684\u7cbe\u529b\u5c06\u4f1a\u7528\u4e8e\u8be6\u7ec6\u8bb2\u89e3\u5982\u4f55\u5229\u7528dockerfile\u6765\u6784\u5efa\u955c\u50cf\u3002<\/span><\/p>\n<p><span class=\"bjh-h3\">\u521b\u5efadocker hub\u8d26\u53f7<\/span><\/p>\n<p><span class=\"bjh-p\">\u5728\u6784\u5efa\u955c\u50cf\u4e2d\uff0c\u5f88\u91cd\u8981\u7684\u4e00\u73af\u5c31\u662f\u5171\u4eab\u548c\u53d1\u5e03\u955c\u50cf\u3002\u901a\u5e38\uff0c\u6211\u4eec\u90fd\u4f1a\u5c06\u955c\u50cf\u63a8\u9001\u5230Docker Hub\u6765\u5171\u4eab\u955c\u50cf\u3002\u6211\u4eec\u9700\u8981\u8fdb\u5165Docker Hub\u9996\u5148\u6ce8\u518c\u4e00\u4e2a\u8d26\u53f7\uff1ahttps:\/\/hub.docker.com\/\u6ce8\u518c\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u5728\u672c\u5730\u7ed1\u5b9a\u5bf9\u5e94\u7684Docker Hub\u8d26\u53f7\u3002<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">sudo docker login<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\"># Username: ***<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\"># Password:<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\"># Email: ***<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\"># Login Succeed<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-h3\">\u4f7f\u7528docker commit\u547d\u4ee4\u6765\u521b\u5efa\u955c\u50cf<\/span><\/p>\n<p><span class=\"bjh-p\">\u521b\u5efaDocker\u955c\u50cf\u7684\u7b2c\u4e00\u79cd\u65b9\u6cd5\u5c31\u662f\u901a\u8fc7commit\u547d\u4ee4\u3002\u6d41\u7a0b\u7b80\u4ecb\u5982\u4e0b\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">\u6839\u636e\u67d0\u4e2a\u955c\u50cf\u521b\u5efa\u4e00\u4e2a\u5bb9\u5668<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">\u5bf9\u8be5\u5bb9\u5668\u8fdb\u884c\u4e00\u4e9b\u4fee\u6539<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">\u63d0\u4ea4\u8be5\u5bb9\u5668\u5e76\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u955c\u50cf\u3002<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u793a\u4f8b\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">sudo docker run -it ubuntu \/bin\/bash<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">root@b3f9427a5039:\/# apt-get -yqq update<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">root@b3f9427a5039:\/# apt-get -y install apache2<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">root@b3f9427a5039:\/# exit<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u53ef\u4ee5\u770b\u5230\uff0c\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u6839\u636eubuntu\u955c\u50cf\u521b\u5efa\u4e86\u4e00\u4e2a\u5bb9\u5668\uff0c\u5bb9\u5668id\u4e3ab3f9427a5039\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5bf9\u8fd9\u4e2a\u5bb9\u5668\u8fdb\u884c\u4e86\u4e00\u4e9b\u4fee\u6539\uff0c\u4f8b\u5982\u5b89\u88c5\u4e86Apache\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u9000\u51fa\u4e86\u8be5\u5bb9\u5668\u3002\u4e0b\u9762\uff0c\u6211\u4eec\u5c06\u4f1a\u4f7f\u7528commit\u547d\u4ee4\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u955c\u50cf\u3002<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">sudo docker commit b3f9427a5039 wangzhe0912\/apache2<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u4e0a\u9762\u7684\u547d\u4ee4\u8868\u793a\u5c06\u6211\u4eec\u521a\u624d\u7684\u5bb9\u5668\u521b\u5efa\u4e3a\u4e00\u4e2awangzhe0912\u7528\u6237\u4e0b\u7684apache\u955c\u50cf\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528docker images\u6765\u67e5\u770b\u662f\u5426\u6709\u8be5\u65b0\u589e\u7684\u955c\u50cf\u3002<\/span><\/p>\n<p><span class=\"bjh-p\">ps\uff1a\u5728commit\u547d\u4ee4\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u6dfb\u52a0\u66f4\u591a\u7684\u53c2\u6570\u6765\u5bf9\u955c\u50cf\u8fdb\u884c\u63cf\u8ff0\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">-m=\u201dmessage\u201d \u53ef\u4ee5\u7528\u4e8e\u5bf9\u63d0\u4ea4\u7684\u955c\u50cf\u6dfb\u52a0\u4e00\u4e9b\u6587\u672c\u63cf\u8ff0<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">\u2013author=\u201dperson\u201d \u53ef\u4ee5\u7528\u4e8e\u6dfb\u52a0\u63d0\u4ea4\u4eba\u4fe1\u606f<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">\u63d0\u4ea4\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u8bbe\u7f6etag\u3002<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u793a\u4f8b\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">sudo docker commit -m=&#8221;install apache&#8221; &#8211;author=&#8221;wangzhe0912&#8243; b3f9427a5039 wangzhe0912\/apache2:v1<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<\/span><\/p>\n<p><span class=\"bjh-p\">docker inspect \u955c\u50cf\u540d<\/span><\/p>\n<p><span class=\"bjh-p\">\u547d\u4ee4\u6765\u67e5\u770b\u955c\u50cf\u7684\u4e00\u4e9b\u8be6\u7ec6\u4fe1\u606f\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">docker inspect wangzhe0912\/apache2:v1<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u4e0b\u9762\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u76f4\u63a5\u6839\u636e\u6211\u4eec\u65b0\u5efa\u7684\u955c\u50cf\u6765\u521b\u5efa\u4e00\u4e2a\u5bb9\u5668\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">sudo docker run -it wangzhe0912\/apache2:v1 \/bin\/bash<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-h3\">\u4f7f\u7528dockerfile\u6765\u6784\u5efa\u955c\u50cf<\/span><\/p>\n<p><span class=\"bjh-p\">\u5728\u4e0a\u9762\u7684\u5185\u5bb9\u4e2d\uff0c\u6211\u4eec\u7b80\u5355\u7684\u8bb2\u89e3\u4e86\u5982\u4f55\u901a\u8fc7commit\u6765\u521b\u5efa\u65b0\u7684\u955c\u50cf\u3002<\/span><\/p>\n<p><span class=\"bjh-p\">\u4e0b\u9762\uff0c\u6211\u4eec\u5c06\u4f1a\u7ee7\u7eed\u5c06\u8bb2\u89e3\u5982\u4f55\u4f7f\u7528Dockerfile\u6765\u521b\u5efa\u955c\u50cf\uff0c\u8fd9\u662f\u4e00\u79cd\u66f4\u52a0\u5f3a\u5927\u548c\u7075\u6d3b\u7684\u65b9\u5f0f\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5de5\u4f5c\u76ee\u5f55\uff0c\u5e76\u5728\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2aDockerfile\u6587\u4ef6\u3002<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">mkdir workdir<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">cd .\/workdir<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">touch Dockerfile<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u8fd9\u4e2a\u76ee\u5f55\u6211\u4eec\u901a\u5e38\u79f0\u4e4b\u4e3a\u6784\u5efa\u73af\u5883\uff0cDocker\u4f1a\u5728\u6784\u5efa\u955c\u50cf\u65f6\u5c06\u6784\u5efa\u4e0a\u4e0b\u6587\u548c\u8be5\u6587\u4ef6\u4e0a\u4e0b\u6587\u7684\u6587\u4ef6\u548c\u76ee\u5f55\u4f20\u9012\u7ed9Docker\u5b88\u62a4\u8fdb\u7a0b\u3002\u6211\u4eec\u7f16\u8f91Dockerfile\u5982\u4e0b\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\"># Version: 0.0.1<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">FROM ubuntu:14.04<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">MAINTAINER Wangzhe0912 &#8220;Wangzhe0912@tju.edu.cn&#8221;<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">RUN apt-get update<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">RUN apt-get install -y nginx<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">RUN echo &#8220;Hi, I am your contrainer&#8221; &gt; \/usr\/share\/nginx\/html\/index.html<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">EXPOSE 80<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u4e0b\u9762\uff0c\u6211\u4eec\u6765\u8be6\u7ec6\u5256\u6790\u4e00\u4e0b\u8fd9\u6bb5\u4ee3\u7801\u7684\u542b\u4e49\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">\u6bcf\u4e2aDockerfile\u7684\u7b2c\u4e00\u884c\u6307\u4ee4\u90fd\u5e94\u8be5\u662fFROM\u5f00\u5934\u3002FROM\u7528\u4e8e\u5236\u5b9a\u4e00\u4e2a\u5df2\u7ecf\u5b58\u5728\u7684\u955c\u50cf\uff0c\u540e\u7eed\u6307\u4ee4\u90fd\u662f\u57fa\u4e8e\u8be5\u955c\u50cf\u6765\u8fd0\u884c\u3002\u8fd9\u4e2a\u955c\u50cf\u6211\u4eec\u79f0\u4e4b\u4e3a\u57fa\u7840\u955c\u50cf\u3002<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">MAINTAINER\u540e\u8bf4\u660e\u8be5\u4f5c\u8005\u548c\u4f5c\u8005\u90ae\u7bb1\u4fe1\u606f\u3002<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">\u63a5\u4e0b\u6765\u662f\u4e09\u6761RUN\u6307\u4ee4\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6307\u4ee4\u540e\u7684\u5185\u5bb9\u4f1a\u901a\u8fc7\/bin\/sh -c\u6765\u6267\u884c\u3002<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">\u6700\u540e\u8bbe\u7f6e\u4e86EXPOSE\uff0c\u8be5\u6307\u4ee4\u7528\u4e8e\u6307\u5b9a\u5bb9\u5668\u5185\u7684\u5e94\u7528\u7a0b\u5e8f\u4f1a\u4f7f\u7528\u54ea\u4e9b\u7aef\u53e3\uff08\u53ef\u4ee5\u6307\u5b9a\u591a\u4e2a\uff09\u3002PS\uff1a\u51fa\u4e8e\u5b89\u5168\u8003\u8651\uff0c\u9ed8\u8ba4Docker\u4e0d\u4f1a\u81ea\u52a8\u6253\u5f00\u8fd9\u4e9b\u7aef\u53e3\uff0c\u9700\u8981\u5728<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">docker run\u6307\u4ee4\u4e2d\u6307\u5b9a\u9700\u8981\u6253\u5f00\u7684\u7aef\u53e3\u3002<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u90a3\u4e48\u8fd9\u6bb5\u4ee3\u7801\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u7684\u673a\u5236\u662f\u4ec0\u4e48\u6837\u5b50\u7684\u5462\uff1f<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">\u9996\u5148\u4ece\u57fa\u7840\u955c\u50cfubuntu:14.04\u4e2d\u542f\u52a8\u4e00\u4e2a\u5bb9\u5668<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">\u6267\u884c\u4e00\u6761run\u6307\u4ee4<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">\u6267\u884c\u7c7b\u4f3c<\/span><span class=\"bjh-p\">commit<\/span><span class=\"bjh-p\">\u6307\u4ee4\uff0c\u63d0\u4ea4\u4e00\u4e2a\u65b0\u7684\u955c\u50cf\u5c42\u3002<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">\u57fa\u4e8e\u6b65\u9aa43\u63d0\u4ea4\u7684\u955c\u50cf\u8fd0\u884c\u4e00\u4e2a\u65b0\u7684\u5bb9\u5668\u3002<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">\u8fd4\u56de\u6b65\u9aa42\uff0c\u7ee7\u7eed\u6267\u884c\u4e0b\u4e00\u6761\u8fd0\u884c\u6307\u4ee4\uff0c\u76f4\u81f3\u6ca1\u6709\u8fd0\u884c\u6307\u4ee4\u3002<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">Ps\uff1a\u8fd9\u6837\u7684\u4f18\u70b9\u7684\u5982\u679c\u5728Dockerfile\u4e2d\uff0c\u5b58\u5728\u67d0\u4e2a\u6b65\u9aa4\u6267\u884c\u5931\u8d25\uff0c\u6211\u4eec\u5c06\u4f1a\u5f97\u5230\u4e0a\u4e00\u6b65\u4e2d\u751f\u6210\u7684\u955c\u50cf\uff0c\u5229\u7528\u8be5\u955c\u50cf\uff0c\u6211\u4eec\u53ef\u4ee5\u8fdb\u884c\u5355\u6b65\u8c03\u8bd5\u3002<\/span><\/p>\n<p><span class=\"bjh-h3\">\u57fa\u4e8edockerfile\u6784\u5efa\u65b0\u955c\u50cf<\/span><\/p>\n<p><span class=\"bjh-p\">\u5f53\u6211\u4eec\u5199\u5b8cDockerfile\u6587\u4ef6\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u6267\u884cdocker build\u547d\u4ee4\u6765\u6267\u884cDockerfile\u4e2d\u7684\u6240\u6709\u6307\u4ee4\u5e76\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u955c\u50cf\u3002<\/span><\/p>\n<p><span class=\"bjh-p\">\u793a\u4f8b\u5982\u4e0b\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">docker build -t=&#8221;wangzhe0912\/nginx:v1&#8243;` .<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u5176\u4e2d\uff0c-t=&#8221;wangzhe0912\/nginx:v1&#8243;\u6307\u5b9a\u4e86\u65b0\u751f\u6210\u955c\u50cf\u7684\u955c\u50cf\u540d\u79f0\u3002 .\u8868\u793a\u7684\u662f\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u5bfb\u627eDockerfile\u6587\u4ef6\u3002<\/span><\/p>\n<p><span class=\"bjh-p\">\u9664\u4e86\u5728\u672c\u5730\u5bfb\u627eDockerfile\u6587\u4ef6\u4e4b\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u76f4\u63a5\u6307\u5b9agit\u4ed3\u5e93\u6765\u5bfb\u627eDockerfile\u6587\u4ef6\u3002<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">docker build -t=&#8221;wangzhe0912\/nginx:v1&#8243;` git@github.com:wangzhe0912\/docker_web<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">Ps\uff1a\u5982\u679c\u5728\u6784\u5efa\u76ee\u5f55\u4e2d\u5b58\u5728.dockerignore\u547d\u4ee4\u7684\u6587\u4ef6\u65f6\uff0c\u90a3\u4e48\u8be5\u6587\u4ef6\u5185\u5bb9\u5c06\u4f1a\u88ab\u6309\u884c\u5206\u5272\uff0c\u6309\u884c\u5339\u914d\u8fc7\u6ee4\uff0c\u7c7b\u4f3c\u4e8e.gitignore\u6587\u4ef6\u3002<\/span><\/p>\n<p><span class=\"bjh-h3\">Dockerfile\u548c\u6784\u5efa\u7f13\u5b58<\/span><\/p>\n<p><span class=\"bjh-p\">Docker\u5728\u6784\u5efa\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u4ece\u5728\u4e00\u5b9a\u7684\u7f13\u5b58\u673a\u5236\u3002\u4f8b\u5982\u6211\u4eec\u4fee\u6539\u4e86Dockerfile\u7684\u7b2c\u4e94\u884c\u540e\u91cd\u65b0\u8fdb\u884c\u6784\u5efa\uff0c\u90a3\u4e48\u6784\u5efa\u8fc7\u7a0b\u4e2d\u524d\u56db\u884c\u5c06\u4e0d\u4f1a\u8fdb\u884c\u91cd\u590d\u6267\u884c\uff0c\u800c\u662f\u76f4\u63a5\u4ece\u7f13\u5b58\u4e2d\u8fdb\u884c\u8bfb\u53d6\u3002\u5982\u679c\u6211\u4eec\u5e0c\u671b\u5f3a\u5236\u5ffd\u7565\u7f13\u5b58\u65f6\uff0c\u53ef\u4ee5\u989d\u5916\u6dfb\u52a0&#8211;no-cache\u53c2\u6570\u8fdb\u884c\u8bbe\u7f6e\u3002<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">sudo docker build &#8211;no-cache -t=&#8221;wangzhe0912\/nginx:v1&#8243; .<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-h3\">\u57fa\u4e8e\u6784\u5efa\u7f13\u5b58\u7684Dockerfile\u6a21\u7248<\/span><\/p>\n<p><span class=\"bjh-p\">\u4e3a\u4e86\u5408\u7406\u5229\u7528\u7f13\u5b58\u673a\u5236\uff0c\u800c\u53c8\u4e0d\u9700\u8981\u624b\u5de5\u6dfb\u52a0\u547d\u4ee4\u5f3a\u5236\u6e05\u9664\u7f13\u5b58\uff0c\u90a3\u4e48\u53ef\u4ee5\u501f\u9274\u5982\u4e0b\u6a21\u677f\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">FROM ubuntu:14.04<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">MAINTAINER Wangzhe0912 &#8220;Wangzhe0912@tju.edu.cn&#8221;<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">ENV REFRESHED_AT 2018-01-28<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">RUN apt-get update<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">&#8230;<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u89c2\u5bdf\u4e00\u4e0b\u8be5\u6a21\u677f\uff0c\u6211\u4eec\u5728\u5176\u4e2d\u6dfb\u52a0\u4e86\u4e00\u884cENV\u3002 ENV\u7684\u4f5c\u7528\u662f\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u800c\u5728\u6b64\u65f6\uff0c\u6211\u4eec\u7684\u76ee\u7684\u662f\u7528\u4e8e\u5237\u65b0\u6784\u5efa\u548c\u7f13\u5b58\uff0c\u5f53ENV\u7684\u503c\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u5c06\u4f1a\u5ffd\u7565\u540e\u7eed\u7684\u7f13\u5b58\uff0c\u91cd\u65b0\u6267\u884c\u3002\u800c\u5f53\u5f53ENV\u7684\u503c\u6ca1\u6709\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u5219\u53ef\u4ee5\u5145\u5206\u5229\u7528\u7f13\u5b58\u7684\u673a\u5236\u5feb\u901f\u6784\u5efa\u3002<\/span><\/p>\n<p><span class=\"bjh-h3\">\u67e5\u770b\u65b0\u955c\u50cf<\/span><\/p>\n<p><span class=\"bjh-p\">\u5f53\u6784\u5efa\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u5c31\u5b8c\u6210\u4e86\u4e00\u4e2a\u65b0\u955c\u50cf\u7684\u6784\u5efa\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u6765\u67e5\u770b\u8be5\u955c\u50cf\u7684\u5b8c\u6574\u6784\u5efa\u8fc7\u7a0b\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">docker history image_name\/id<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-h3\">\u4ece\u65b0\u955c\u50cf\u542f\u52a8\u5bb9\u5668<\/span><\/p>\n<p><span class=\"bjh-p\">\u4e0b\u9762\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u521a\u624d\u6784\u5efa\u7684\u955c\u50cf\u6765\u8be6\u7ec6\u4e86\u89e3\u4e00\u4e0bnginx\u955c\u50cf\u8be5\u5982\u4f55\u8fd0\u884c\u548c\u4f7f\u7528\u3002\u4e0b\u9762\u6211\u4eec\u4ee5\u5982\u4e0b\u547d\u4ee4\u8fdb\u884c\u8bb2\u89e3\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">docker run -d -p 80 &#8211;name wangzhe_nginx wangzhe0912\/nginx:v1 nginx -g &#8220;daemon off;&#8221;<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u5176\u4e2d\uff1a<\/span><\/p>\n<p><span class=\"bjh-ul\"><span class=\"bjh-li\"><span class=\"bjh-p\">-d<\/span><span class=\"bjh-p\">\u8868\u793a\u4ee5\u540e\u53f0\u7a0b\u5e8f\u8fdb\u884c\u8fd0\u884c<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">-p 80<\/span><span class=\"bjh-p\">\u7528\u4e8e\u6307\u5b9a\u5728\u8fd0\u884c\u65f6\u516c\u5f0080\u7aef\u53e3\u7ed9\u5bbf\u4e3b\u673a\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5bbf\u4e3b\u673a\u4f1a\u5728\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u7aef\u53e3\u53f7\u6620\u5c04\u5230\u5bb9\u5668\u768480\u7aef\u53e3\u4e0a\u3002\u5f53\u7136\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u6307\u5b9a\u7528\u5bbf\u4e3b\u673a\u7684\u67d0\u4e2a\u7aef\u53e3\uff08\u4f8b\u59828080\uff09\u6765\u6620\u5c04\u5230\u5bb9\u5668\u768480\u7aef\u53e3\uff0c\u4f7f\u7528\u65b9\u5f0f\u5982\u4e0b\uff1a-p 8080:80\u3002\u5f53\u7136\uff0c\u8fd8\u6709\u4e00\u79cd\u66f4\u52a0\u7b80\u5355\u7684\u65b9\u5f0f\uff0c\u4e4b\u524d\u6211\u4eec\u5728Dockerfile\u6587\u4ef6\u4e2d\u6307\u5b9a\u4e86EXPOSE\u5bf9\u5e94\u7aef\u53e3\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528-P\u6765\u6253\u5f00\u5728Dockerfile\u6587\u4ef6\u4e2d\u6307\u5b9a\u7684\u7aef\u53e3\u3002<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">&#8211;name wangzhe_nginx<\/span><span class=\"bjh-p\">\u6307\u5b9a\u5bb9\u5668\u7684\u540d\u79f0<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">nginx -g &#8220;daemon off;&#8221;<\/span><span class=\"bjh-p\">\u8868\u793a\u4e86\u5bb9\u5668\u9700\u8981\u6267\u884c\u7684\u547d\u4ee4\u3002<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u8fd0\u884c\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u9700\u8981\u67e5\u770b\u4e00\u4e0b\u6211\u4eec\u7684\u5bb9\u5668\u6620\u5c04\u5230\u4e86\u5bbf\u4e3b\u673a\u7684\u54ea\u4e2a\u7aef\u53e3\u4e2d\u3002\u53ef\u4ee5\u6267\u884c\u5982\u4e0b\u547d\u4ee4docker ps\u6765\u67e5\u770b\uff1a<\/span><\/p>\n<div class=\"img-container\"><img decoding=\"async\" class=\"large\" src=\"https:\/\/ss0.baidu.com\/6ONWsjip0QIZ8tyhnq\/it\/u=1248565857,1976740011&amp;fm=173&amp;w=640&amp;h=49&amp;img.JPEG\" data-loadfunc=\"0\" data-loaded=\"0\" \/><\/div>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5bbf\u4e3b\u673a\u768432768\u7aef\u53e3\u6307\u5411\u4e86\u5bb9\u5668\u768480\u7aef\u53e3\u3002\u8fd8\u6709\u4e00\u79cd\u66f4\u52a0\u7b80\u5355\u7684\u7aef\u53e3\u6620\u5c04\u67e5\u8be2\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">docker port wangzhe_nginx 80<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\"># 0.0.0.0:32768<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u5373\u6307\u5b9a\u5bb9\u5668\u540d\u79f0\u548c\u5bb9\u5668\u7aef\u53e3\uff0c\u53ef\u4ee5\u76f4\u63a5\u67e5\u8be2\u6620\u5c04\u7684\u7aef\u53e3\u5730\u5740\u3002\u4e0b\u9762\uff0c\u6211\u4eec\u6765\u8bbf\u95ee\u4e00\u4e0b\u8be5\u5730\u5740\uff0c\u770b\u4e0b\u6211\u4eec\u7684nginx\u670d\u52a1\u662f\u5426\u5df2\u7ecf\u6b63\u5e38\u542f\u52a8\u3002<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">curl localhost:32768<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\"># Hi, I am your contrainer<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-h3\">Dockerfile\u6307\u4ee4<\/span><\/p>\n<p><span class=\"bjh-p\">\u5728\u4e4b\u524d\u7684\u5b66\u4e60\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u5b66\u4e60\u5230\u4e86\u4e00\u90e8\u5206Dockerfile\u6307\u4ee4\uff0c\u4f8b\u5982FROM, ENV, RUN, EXPOSE\u7b49\uff0c\u5728\u672c\u8282\u4e2d\uff0c\u6211\u4eec\u5c06\u4f1a\u8be6\u7ec6\u5b66\u4e60\u76f8\u5173\u7684\u4e00\u7cfb\u5217\u6307\u4ee4\u3002<\/span><\/p>\n<p><span class=\"bjh-p\">1.CMDCMD\u662f\u4e00\u4e2a\u5bb9\u5668\u542f\u52a8\u65f6\u8981\u8fd0\u884c\u7684\u547d\u4ee4\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u4e4b\u524d\u542f\u52a8\u4e00\u4e2a\u5bb9\u5668\u65f6\u7684\u4ee3\u7801\u7c7b\u4f3c\u5982\u4e0b\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">docker run -it wangzhe0912\/nginx \/bin\/bash<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u5176\u4e2d\uff0c\/bin\/bash\u8868\u793a\u7684\u662f\u542f\u52a8\u5bb9\u5668\u65f6\u9700\u8981\u6267\u884c\u7684\u547d\u4ee4\u3002<\/span><\/p>\n<p><span class=\"bjh-p\">\u53ef\u4ee5\u7b49\u6548\u5982\u4e0b\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">CMD [&#8220;\/bin\/bash&#8221;]<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u6b64\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u7ed9\u8fd0\u884c\u547d\u4ee4\u53c2\u6570\u76f8\u5173\u53c2\u6570\uff0c\u4f8b\u5982\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">CMD [&#8220;\/bin\/bash&#8221;, &#8220;-l&#8221;]<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">PS\uff1a\u5728\u542f\u52a8\u5bb9\u5668\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7docker run\u547d\u4ee4\u6765\u8986\u76d6CMD\u6307\u4ee4\u3002\u8fd8\u6709\u5728Dockerfile\u4e2d\u53ea\u80fd\u6307\u5b9a\u4e00\u6761CMD\u6307\u4ee4\uff0c\u5982\u679c\u6307\u5b9a\u591a\u6761\uff0c\u6700\u540e\u4e00\u6761CMD\u6307\u4ee4\u5c06\u4f1a\u751f\u6548\u3002<\/span><\/p>\n<p><span class=\"bjh-p\">2.ENTRYPOINTENTRYPOINT\u4e0eCMD\u5341\u5206\u7c7b\u4f3c\uff0c\u76f8\u6bd4\u8f83\u800c\u8a00ENTRYPOINT\u66f4\u4e0d\u5bb9\u6613\u88ab\u8986\u76d6\u3002\u7b80\u5355\u7684\u8bf4\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u8bbe\u7f6e\u53ef\u6267\u884c\u6587\u4ef6\u5728ENTRYPOINT\u4e2d\uff0c\u800c\u5728CMD\u4e2d\u8bbe\u7f6e\u9700\u8981\u4f20\u5165\u7684\u53c2\u6570\u3002\u56e0\u4e3a\u901a\u5e38\u800c\u8a00\uff0c\u9ed8\u8ba4\u8fd0\u884c\u7684\u53ef\u6267\u884c\u6587\u4ef6\u901a\u5e38\u4e0d\u4f1a\u53d1\u751f\u53d8\u5316\uff0c\u4f46\u662f\u53c2\u6570\u53d8\u5316\u5219\u76f8\u5bf9\u53ef\u80fd\u4f1a\u9891\u7e41\u4e00\u4e9b\u3002\u793a\u4f8b\u5982\u4e0b\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">ENTRYPOINT [&#8220;\/usr\/sbin\/nginx&#8221;]<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">CMD [&#8220;-h&#8221;]<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">Ps\uff1a\u5982\u679c\u6709\u9700\u8981\uff0c\u53ef\u4ee5\u5728docker run\u65f6\uff0c\u4f7f\u7528&#8211;entrypoint=&#8221;***&#8221;<\/span><\/p>\n<p><span class=\"bjh-p\">\u6765\u5f3a\u5236\u8986\u76d6ENTRYPOINT\u3002<\/span><\/p>\n<p><span class=\"bjh-p\">3.WORKDIRWORKDIR\u7528\u4e8e\u5728\u5bb9\u5668\u5185\u8bbe\u7f6e\u5de5\u4f5c\u76ee\u5f55\uff0cENTRYPOINT\u548cCMD\u547d\u4ee4\u4f1a\u5728\u6307\u5b9a\u7684\u76ee\u5f55\u4e0b\u6267\u884c\u3002\u793a\u4f8b\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">WORKDIR \/opt\/webapp<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">RUN bundle install<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">WORKDIR \/opt\/webapp\/db<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">ENTRYPOINT [&#8220;rackup&#8221;]<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">Ps\uff1a-w\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u8986\u76d6\u5de5\u4f5c\u76ee\u5f55\u3002<\/span><\/p>\n<p><span class=\"bjh-p\">\u4f8b\u5982\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">docker run -it -w \/var\/log ubuntu pwd<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">4.ENV\u5728\u955c\u50cf\u6784\u5efa\u8fc7\u7a0b\u4e2d\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u65b0\u8bbe\u7f6e\u7684\u73af\u5883\u53d8\u91cf\u53ef\u4ee5\u5728\u540e\u7eed\u4efb\u4f55\u7684RUN\u6307\u4ee4\u4e2d\u4f7f\u7528\u3002<\/span><\/p>\n<p><span class=\"bjh-p\">\u793a\u4f8b\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">ENV RVM_PATH \/home\/rvm\/<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">RUN gem install unicorn<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">PS\uff1a\u5728\u8fd0\u884c\u65f6\u53ef\u4ee5\u4f7f\u7528-e\u6765\u4f20\u9012\u73af\u5883\u53d8\u91cf\uff0c\u793a\u4f8b\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">docker run -it -e &#8220;WEB_PORT=8080&#8221; pwd<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">5.USERUSER\u6307\u4ee4\u7528\u4e8e\u8bbe\u5b9a\u8be5\u955c\u50cf\u4f1a\u4ee5\u4ec0\u4e48\u7528\u6237\u53bb\u6267\u884c\u3002\u9ed8\u8ba4\u4f1a\u4ee5root\u7528\u6237\u6267\u884c\u3002\u53ef\u4ee5\u5728\u8fd0\u884c\u547d\u4ee4\u4e2d\u4f7f\u7528-u\u8fdb\u884c\u8986\u76d6\u3002<\/span><\/p>\n<p><span class=\"bjh-p\">\u793a\u4f8b\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">docker run -it -u &#8220;nginx&#8221; pwd<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">6.VOLUMNVOLUMN\u7528\u6237\u6307\u5b9a\u5411\u57fa\u4e8e\u955c\u50cf\u521b\u5efa\u7684\u5bb9\u5668\u6dfb\u52a0\u5377\u3002\u5377\u662f\u6307\u53ef\u4ee5\u5b58\u5728\u4e8e\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u5bb9\u5668\u5185\u7684\u7279\u5b9a\u76ee\u5f55\uff0c\u8fd9\u4e2a\u76ee\u5f55\u53ef\u4ee5\u7ed5\u8fc7\u8054\u5408\u6587\u4ef6\u7cfb\u7edf\u6765\u5171\u4eab\u6570\u636e\u6216\u8005\u6570\u636e\u6301\u4e45\u5316\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5377\u7684\u7279\u70b9\uff1a<\/span><\/p>\n<p><span class=\"bjh-ul\"><span class=\"bjh-li\"><span class=\"bjh-p\">\u5377\u53ef\u4ee5\u5728\u5bb9\u5668\u4e2d\u5171\u4eab\u548c\u91cd\u7528\u3002<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">\u5bf9\u5377\u7684\u4fee\u6539\u662f\u5b9e\u65f6\u751f\u6548\u3002<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">\u5bf9\u5377\u7684\u4fee\u6539\u4e0d\u4f1a\u5f71\u54cd\u955c\u50cf\u3002<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">\u5377\u4f1a\u4e00\u76f4\u5b58\u5728\u5230\u6ca1\u6709\u5bb9\u5668\u4f7f\u7528\u4ed6\u3002<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u5377\u529f\u80fd\u53ef\u4ee5\u5c06\u6570\u636e\u3001\u4ee3\u7801\u3001\u6570\u636e\u5e93\u7b49\u4fe1\u606f\u6dfb\u52a0\u5230\u955c\u50cf\u800c\u4e0d\u662f\u628a\u8fd9\u4e9b\u5185\u5bb9\u63d0\u4ea4\u5230\u955c\u50cf\u3002\u4f7f\u7528\u793a\u4f8b\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">VOLUMN [&#8220;\/opt\/project&#8221;, &#8220;\/data&#8221;]<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">7.ADDADD\u6307\u4ee4\u7528\u4e8e\u5c06\u6784\u5efa\u73af\u5883\u4e0b\u7684\u6587\u4ef6\u548c\u76ee\u5f55\u590d\u5236\u5230\u955c\u50cf\u4e2d\u3002\u5e38\u7528\u7684\u573a\u666f\u4f8b\u5982\u5b89\u88c5\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u3002ADD\u6307\u4ee4\u9700\u8981\u6e90\u6587\u4ef6\u548c\u76ee\u7684\u6587\u4ef6\u4f4d\u7f6e\u4e24\u4e2a\u53c2\u6570\u3002\u793a\u4f8b\u4ee3\u7801\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">ADD software.lic \/opt\/applicaion\/software.lic<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">Ps\uff1aADD\u547d\u4ee4\u672c\u8eab\u6765\u6709\u4e00\u4e9b\u76f8\u5bf9\u9700\u8981\u6ce8\u610f\u7684\u70b9\uff1aADD\u547d\u4ee4\u53ef\u4ee5\u81ea\u52a8\u5c06\u4e00\u4e9b\u538b\u7f29\u6587\u4ef6\u8fdb\u884c\u81ea\u52a8\u89e3\u538b\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">ADD latest.tar.gz \/var\/www\/wordpress\/<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u6b64\u5916\uff0c\u5982\u679c\u76ee\u7684\u6587\u4ef6\u5939\u4e0d\u5b58\u5728\u7684\u8bdd\uff0cDocker\u4f1a\u81ea\u52a8\u5e2e\u52a9\u6211\u4eec\u521b\u5efa\u5b8c\u6574\u7684\u8def\u5f84\u3002\u65b0\u521b\u5efa\u7684\u6587\u4ef6\u548c\u76ee\u5f55\u7684\u6743\u9650\u90fd\u662f0755\u3002\u8fd8\u6709\u4e00\u70b9\u662fADD\u6307\u4ee4\u4f1a\u4f7f\u4e4b\u524d\u7684\u7f13\u5b58\u5168\u90e8\u5931\u6548\u3002<\/span><\/p>\n<p><span class=\"bjh-p\">8.COPYCOPY\u6307\u4ee4\u4e0eADD\u6307\u4ee4\u76f8\u7c7b\u4f3c\uff0c\u4e0d\u8fc7COPY\u53ea\u5173\u6ce8\u4e0e\u590d\u5236\u6587\u4ef6\uff0c\u800c\u4e0d\u4f1a\u505a\u6587\u4ef6\u7684\u63d0\u53d6\u548c\u89e3\u538b\u3002<\/span><\/p>\n<p><span class=\"bjh-p\">9.ONBUILDONBUILD\u6307\u4ee4\u53ef\u4ee5\u4e3a\u955c\u50cf\u6dfb\u52a0\u89e6\u53d1\u5668\u3002\u5f53\u4e00\u4e2a\u955c\u50cf\u88ab\u5176\u4ed6\u955c\u50cf\u7528\u4f5c\u57fa\u7840\u955c\u50cf\u65f6\uff0c\u8be5\u955c\u50cf\u7684\u89e6\u53d1\u5668\u4f1a\u6267\u884c\u3002\u89e6\u53d1\u5668\u53ef\u4ee5\u662f\u4efb\u4f55\u6784\u5efa\u6307\u4ee4\uff0c\u901a\u5e38\u662f\u7d27\u8ddf\u5728FROM\u540e\u9762\u7684\u3002<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">ONBUILD ADD . \/app\/src<\/span><\/span><span class=\"bjh-li\"><span class=\"bjh-p\">ONBUILD RUN cd \/app\/src &amp;amp;&amp;amp; make<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-h3\">\u5c06\u955c\u50cf\u63a8\u9001\u81f3Docker Hub<\/span><\/p>\n<p><span class=\"bjh-p\">\u5f53\u6211\u4eec\u5b8c\u6210\u955c\u50cf\u7684\u6784\u5efa\u540e\uff0c\u53ef\u4ee5\u5c06\u5176\u4e0a\u4f20\u5230Docker Hub\u4e2d\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528docker push\u547d\u4ee4\u6765\u63a8\u9001Docker\u955c\u50cf\u3002<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">sudo docker push wangzhe0912\/nginx<\/span><\/span><\/span><\/p>\n<p>\u63a8\u9001\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6211\u4eec\u7684Docker Hub\u4e2d\u770b\u5230\u6211\u4eec\u4e0a\u4f20\u7684\u955c\u50cf\u3002<\/p>\n<div class=\"img-container\"><img decoding=\"async\" class=\"large\" src=\"https:\/\/ss1.baidu.com\/6ONXsjip0QIZ8tyhnq\/it\/u=2980630216,3399925686&amp;fm=173&amp;w=640&amp;h=93&amp;img.JPEG\" data-loadfunc=\"0\" data-loaded=\"0\" \/><\/div>\n<p><span class=\"bjh-h3\">\u81ea\u52a8\u6784\u5efa<\/span><\/p>\n<p><span class=\"bjh-p\">\u9664\u4e86\u6211\u4eec\u901a\u8fc7\u547d\u4ee4\u884c\u6784\u5efa\u540e\u63a8\u9001\u955c\u50cf\u4e4b\u5916\uff0cDocker Hub\u672c\u8eab\u6765\u652f\u6301\u81ea\u52a8\u6784\u5efa\u3002\u81ea\u52a8\u6784\u5efa\u53ea\u9700\u8981\u6211\u4eec\u5c06Github\u4e2d\u542b\u6709Dockerfile\u6587\u4ef6\u7684\u4ed3\u5e93\u8fde\u63a5\u5230Docker Hub\u5373\u53ef\u3002\u6bcf\u6b21\u63a8\u9001\u4ee3\u7801\u540e\uff0c\u4f1a\u81ea\u52a8\u89e6\u53d1\u6784\u5efa\u4e00\u4e2a\u65b0\u7684\u955c\u50cf\u3002<\/span><\/p>\n<p><span class=\"bjh-h3\">\u5220\u9664\u955c\u50cf<\/span><\/p>\n<p><span class=\"bjh-p\">\u5f53\u6211\u4eec\u4e0d\u518d\u9700\u8981\u67d0\u4e00\u4e2a\u955c\u50cf\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5220\u9664\u8be5\u955c\u50cf\u3002\u5220\u9664\u955c\u50cf\u7684\u65b9\u5f0f\u5982\u4e0b\uff1a<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">sudo docker rmi \u955c\u50cf\u540d\u79f0<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u6267\u884c\u8be5\u547d\u4ee4\u540e\uff0c\u6211\u4eec\u53ea\u662f\u4f1a\u5220\u9664\u672c\u5730\u7684\u955c\u50cf\uff0c\u5728Docker Hub\u4e2d\u7684\u955c\u50cf\u5219\u4e0d\u4f1a\u81ea\u52a8\u5220\u9664\u3002<\/span><\/p>\n<p><span class=\"bjh-h3\">\u642d\u5efa\u81ea\u5df1\u7684Dockers Registry<\/span><\/p>\n<p><span class=\"bjh-p\">\u5229\u7528Docker\u5bb9\u5668\u5b89\u88c5\u4e00\u4e2aRegistry\u5341\u5206\u7b80\u5355\uff0c\u53ea\u9700\u8981\u8fd0\u884c\u5bf9\u5e94\u7684\u5bb9\u5668\u5373\u53ef\u3002<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">docker run -d -p 5000:5000 registry<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u6b64\u65f6\uff0c\u6211\u4eec\u5df2\u7ecf\u542f\u52a8\u4e86\u4e00\u4e2a\u672c\u5730\u7684registry\u3002\u4e0b\u9762\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u672c\u5730\u7684registry\u4e3a\u6211\u4eec\u60f3\u8981\u63a8\u9001\u7684\u955c\u50cf\u6253\u597d\u6807\u7b7e\u3002<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">docker tag \u955c\u50cfid 127.0.0.1:5000\/wangzhe0912\/nginx<\/span><\/span><\/span><\/p>\n<p><span class=\"bjh-p\">\u7136\u540e\u76f4\u63a5\u76f4\u63a5docker push\u547d\u4ee4\u6765\u63a8\u9001\u5373\u53ef\u3002<\/span><\/p>\n<p><span class=\"bjh-ol\"><span class=\"bjh-li\"><span class=\"bjh-p\">docker push 127.0.0.1:5000\/wangzhe0912\/nginx<\/span><\/span><\/span><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4e4b\u524d\u7684\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u8bb2\u89e3\u4e86\u4ec0\u4e48\u662fDo<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[122],"class_list":["post-2912","post","type-post","status-publish","format-standard","hentry","tag-06-godocker"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/2912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=2912"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/2912\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=2912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=2912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=2912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}