{"id":26821,"date":"2013-09-17T15:35:09","date_gmt":"2013-09-17T07:35:09","guid":{"rendered":"http:\/\/www.yankay.com\/?p=26819"},"modified":"2021-03-28T20:04:42","modified_gmt":"2021-03-28T12:04:42","slug":"docker-paas-for-any-application","status":"publish","type":"post","link":"http:\/\/yankay.com\/docker-paas-for-any-application\/","title":{"rendered":"Docker\u80fd\u591f\u8fd0\u884c\u4efb\u4f55\u5e94\u7528\u7684\u201cPaaS\u201d\u4e91"},"content":{"rendered":"
Docker <\/a>\u662f\u4e00\u4e2a\u5f00\u6e90\u53ef\u4ee5\u5c06\u4efb\u4f55\u5e94\u7528<\/strong>\u5305\u88c5\u5728”LXC\u5bb9\u5668\u201d\u4e2d\u8fd0\u884c\u7684\u5de5\u5177\u3002\u5982\u679c\u8bf4VMware,KVM\u5305\u88c5\u7684\u865a\u62df\u673a\uff0cDocker\u5305\u88c5\u7684\u662f\u5e94\u7528\u3002\u662f\u4e00\u4e2a\u5b9e\u81f3\u540d\u5f52\u7684PaaS\u3002<\/p>\n \u5f53\u5e94\u7528\u88ab\u6253\u5305\u6210Docker Image\u540e\uff0c\u90e8\u7f72\u548c\u8fd0\u7ef4\u5c31\u53d8\u5f97\u6781\u5176\u7b80\u5355\u3002\u53ef\u4ee5\u4f7f\u7528\u7edf\u4e00\u7684\u65b9\u5f0f <\/strong>\u6765\u4e0b\u8f7d\uff0c\u542f\u52a8\uff0c\u6269\u5c55\uff0c\u5220\u9664\uff0c\u8fc1\u79fb\u3002<\/p>\n <\/p>\n Dock\u53ef\u4ee5\u7528\u6765\uff1a<\/p>\n Docker\u662f\u5f00\u6e90\u7684\uff0c\u53ef\u4ee5\u5728GitHub<\/a>\u4e0a\u8bbf\u95ee\u5176\u4ee3\u7801\uff0c\u63d0\u4f9bRestful\u63a5\u53e3\u3002\u4ed6\u7684\u8d21\u732e\u8005\u662f\u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u7684PaaS\u4e91\u63d0\u4f9b\u5546\u00a0https:\/\/dotcloud.com\/<\/a><\/p>\n \u4e91\u8ba1\u7b97\u53d1\u5c55\u591a\u5e74\uff0c\u5206\u4e3aIaaS,PaaS\u548cSaaS\u3002\u5176\u4e2dPaaS\uff08\u5e73\u53f0\u5373\u670d\u52a1\uff09\u6700\u4e3a\u4e0d\u6120\u4e0d\u706b\u3002\u7b14\u8005\u56e0\u4e3a\uff0c\u6700\u5927\u7684\u539f\u56e0\u662fPaaS\u7ed9\u4eba(\u5f00\u53d1\uff0c\u8fd0\u7ef4\uff0c\u8001\u677f)\u5e26\u6765\u7684\u4ef7\u503c\u4e0d\u591f\u591a\uff0c\u79c1\u6709PaaS\u95e8\u69db\u9ad8\uff01\u6700\u5927\u7684\u95ee\u9898\u5728\u4e8e\u7edd\u5927\u90e8\u5206\u5e94\u7528\u7adf\u7136\u4e0d\u80fd\u65e0\u7f1d\u8fc1\u79fb\u5230PaaS\u4e0a\u3002<\/p>\n Heroku\u662f\u6700\u6d41\u884c\u7684\u516c\u6709PaaS\u4e91\u3002\u5f88\u5ec9\u4ef7\u597d\u7528\uff0c\u53ef\u662f\u5927\u90e8\u5206\u5e94\u7528\u90fd\u65e0\u6cd5\u90e8\u7f72\u3002\u6bcf\u4e2a\u5e94\u7528\u53ea\u80fd\u76d1\u542c\u4e00\u4e2aHTTP\u7aef\u53e3\uff0c\u5e94\u7528\u4e4b\u95f4\u4e0d\u80fd\u4ea4\u4e92\u3002\u4ed6\u53ef\u4ee5\u4e3a\u4f60\u81ea\u52a8\u6269\u5c55\u548c\u8d1f\u8f7d\u5747\u8861\uff0c\u4f46\u5176\u5b9e\u6ca1\u5f97\u9009\u62e9\uff0c\u53ea\u8981\u4f7f\u7528Heroku\u5c31\u5fc5\u987b\u63a5\u53d7\u9650\u5236\u3002\u597d\u6b79Heroku\u652f\u6301\u7edd\u5927\u90e8\u5206\u5e73\u53f0\u5982Java,Python\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0cGAE\u66f4\u751a\uff0c\u53ea\u652f\u6301\u4e09\u4e2a\u5e73\u53f0\uff0c\u4e0d\u80fd\u8bbf\u95ee\u6587\u4ef6\u7cfb\u7edf\uff0c\u4e5f\u4e0d\u80fd\u542f\u52a8\u5b50\u8fdb\u7a0b\u3002<\/p>\n CloudFoundry\u662f\u6bd4\u8f83\u6d41\u884c\u7684\u79c1\u6709PaaS\u4e91\u3002\u9650\u5236\u548cHeroku\u4e00\u6837\u591a\uff0c\u90e8\u7f72\u6bd4\u8f83\u590d\u6742\u3002\u4e3a\u6b64\u4ed6\u751a\u81f3\u6709\u4e00\u4e2a\u91cf\u8eab\u5b9a\u5236\u7684\u90e8\u7f72\u5de5\u5177BOSH\u3002\u6709\u591a\u96be\u7528\uff0c\u7528\u8fc7\u7684\u4eba\u90fd\u77e5\u9053\u3002\u8fd9\u4e2a\u4e0d\u80fd\u602a\u5f00\u53d1\u4eba\u5458\uff0c\u4ed6\u5b9a\u4e49\u7684PaaS\u672c\u6765\u5c31\u8fd9\u4e48\u590d\u6742\u3002<\/p>\n \u5f00\u53d1\u4eba\u5e0c\u671b\u4e13\u6ce8\u4e8e\u7a0b\u5e8f\u903b\u8f91\u3002\u6709\u81ea\u7531\u81ea\u5728\u7684\u8fd0\u884c\u73af\u5883\uff0c\u6709\u4e30\u5bcc\u7684\u5916\u90e8\u8d44\u6e90\u5982\u5404\u79cd\u4e2d\u95f4\u4ef6\u3002\u81f3\u5c11\u4e0d\u8981\u4e3a\u4ec0\u4e48 \u7aef\u53e3\u76d1\u542c\u6570\u76ee\uff0c\u901a\u4fe1\u534f\u8bae\u9650\u5236 \u8fd9\u4e9b\u4e8b\u60c5\u6240\u56f0\u6270\u3002<\/p>\n \u8fd0\u7ef4\u5929\u5929\u5904\u7406\u6545\u969c\uff0c\u5982\u679c\u5343\u5343\u4e07\u5e94\u7528\u90fd\u80fd\u4ee5\u540c\u6837\u7684\u65b9\u5f0f\u90e8\u7f72\uff0c\u8fd0\u7ef4\u3002\u90a3\u4e48\u6545\u969c\u7684\u5904\u7406\u5c31\u7b80\u5355\u591a\u4e86\uff0c\u91cd\u590d\u7684\u4e8b\u60c5\u4e5f\u4f1a\u53d8\u5c11\u3002\u4e0b\u8f7d\u90e8\u7f72\uff0c\u5b89\u88c5\u4f9d\u8d56\uff0c\u8fd9\u4e9b\u4e8b\u60c5\u90fd\u592a\u8fc7\u7e41\u7410\u8017\u65f6\u4e86\u3002<\/p>\n Docker\u53ef\u4ee5\u8ba9\u5f00\u53d1\u548c\u8fd0\u7ef4\u90fd\u53d8\u5f97\u7b80\u5355\u3002<\/p>\n \u5f00\u53d1\u8005\u4e0d\u5fc5\u8981\u50cf\u4f7f\u7528\u4e00\u822cPaaS\u4e00\u6837\u5728\u5145\u6ee1\u7740\u9650\u5236\u7684\u6761\u4ef6\u4e0b\u5f00\u53d1\u5e94\u7528\uff0c\u53ef\u4ee5\u5c31\u5982\u540c\u5e73\u5e38\u4e00\u6837\uff0c\u81ea\u7531\u7684\u4f7f\u7528\u5404\u79cd\u8d44\u6e90\u3002\u8001\u5b50\u8bf4\u201c\u592a\u4e0a\u4e0b\u77e5\u6709\u4e4b \uff0c\u5176\u6b21\u8a89\u4e4b\uff0c\u5176\u6b21\u4fae\u4e4b\u201d\u3002Dock\u5bf9\u4e8e\u5f00\u53d1\u8005\u5c31\u662f\u201c\u4e0b\u77e5\u6709\u4e4b\u201d\u7684\u72b6\u6001\u3002<\/p>\n \u723d\u7684\u4eba\u662f\u8fd0\u7ef4\u3002\u8981\u4f7f\u7528Docker\uff0c\u9700\u8981\u5728\u673a\u5668\u4e0a\u5b89\u88c5Docker Engine\uff0c<\/p>\n \u9700\u8981\u91cd\u542f\u7684\u65f6\u5019\uff0c\u53ea\u8981\u91cd\u542fContainer\u3002\u9700\u8981\u8fc1\u79fb\u7684\u65f6\u5019\uff0c\u53ea\u8981\u8fc1\u79fbContainer\u3002\u4e00\u5207\u5e72\u5e72\u51c0\u51c0\u3002<\/p>\n IaaS\u666e\u904d\u4f7f\u7528\u865a\u62df\u673a,\u5f00\u9500\u8f83\u5927\u3002Docker\u660e\u663e\u66f4\u8f7b\u91cf\u3002\u7b14\u8005\u8ba4\u4e3aIaaS\u548cPaaS\u5404\u6709\u4e13\u653b\uff0cPaaS\u53bb\u4e13\u6ce8\u4e8e\u5b89\u5168\u7ea7\u522b\u7684\u9694\u79bb\u662f\u6ca1\u6709\u610f\u4e49\u7684\uff0cIaaS\u4e5f\u4e0d\u5e94\u8be5\u53bb\u611f\u77e5\u5230\u5e94\u7528\u3002\u4e00\u4e2a\u516c\u6709\u4e91\u4e2d\uff0c\u53ef\u4ee5\u8ba9\u6bcf\u4e2a\u79df\u6237\u4f7f\u7528\u4e0d\u540c\u7684\u865a\u62df\u673a\uff0c\u865a\u62df\u7f51\u7edc\u6765\u505a\u5230\u5b89\u5168\u548c\u8d44\u6e90\u4e0a\u7684\u9694\u79bb\u3002\u518d\u901a\u8fc7PaaS\u7edf\u4e00\u8fd0\u7ef4\uff0c\u7ba1\u7406\u8ba1\u7b97\u8d44\u6e90\u3002<\/p>\n \u6ca1\u6709\u5fc5\u8981\u8ba9\u6bcf\u4e2a\u5e94\u7528\u90fd\u4e13\u4eab\u4e00\u53f0\u865a\u62df\u673a\uff0c\u8fd9\u6837\u5f00\u9500\u592a\u5927\u3002\u4f46\u5728\u5b89\u5168\u654f\u611f\u7684\u73af\u5883\u4e2d\uff0c\u6bcf\u4e2a\u79df\u6237\u4f7f\u7528\u4e0d\u540c\u7684\u865a\u62df\u673a\u662f\u5408\u7406\u7684\u3002<\/p>\n \u4f7f\u7528Docker\u6700\u4fbf\u6377\u7684\u65b9\u5f0f\u83ab\u8fc7\u4e8e \u5728\u7ebf\u5c1d\u8bd5<\/strong>:\u00a0http:\/\/www.docker.io\/gettingstarted\/#<\/a><\/p>\n \u5b8c\u6210\u4e86\u8fd9\u4e2a\u5728\u7ebf\u7684\u6559\u6750\uff0c\u76f8\u4fe1\u4f60\u5bf9Docker\u5df2\u7ecf\u57fa\u672c\u73a9\u8f6c\u4e86\u3002<\/p>\n \u73b0\u5728Docker\u652f\u6301\u4e24\u4e2aUbuntu\u7248\u672c\uff1a<\/p>\n \u6709\u4e24\u4e2a\u4f9d\u8d56<\/p>\n \u6240\u4ee5\u9700\u8981\u786e\u8ba4\u4e0b\u60a8\u7684\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5b89\u88c5\u4f9d\u8d56\u5e76\u91cd\u542f\uff1a<\/p>\n \u5b89\u88c5Docker\u5e76\u91cd\u542f\uff1a<\/p>\n \u4f7f\u7528Docker\uff0c\u4e0b\u8f7d\u4e00\u4e2aUbuntu Image\uff0c\u5e76\u521b\u5efa\u4e00\u4e2aContainer\uff0c\u5728\u5176\u4e2d\u8fd0\u884cBash<\/p>\n \u6210\u529f\uff0c\u4f60\u5df2\u7ecf\u73a9\u8f6cDocker\u4e86\uff01\uff01<\/p>\n \u5f53\u7528\u6237\u6267\u884cDocker run\u7684\u65f6\u5019\uff0c\u53d1\u751f\u4e86\u8fd9\u4e9b\u4e8b\u60c5\uff1a<\/p>\n \u521b\u5efa\u4e00\u4e2aDocker Container<\/p>\n \u5b89\u88c5Redis .<\/p>\n \u62cd\u4e2a\u5feb\u7167\uff0c\u521b\u5efa\u4f60\u81ea\u5df1\u7684Docker Redis Image<\/p>\n \u8fd0\u884cRedis\u3002-d \u662f\u6307\u540e\u53f0\u8fd0\u884c\uff0c\u4f7f\u7528\u4f60\u521a\u521a\u521b\u5efa\u7684Image\u3002<\/p>\n \u4f7f\u7528redis-cli\u8bbf\u95ee<\/p>\n \u4e00\u822c\u6765\u8bf4\uff0c\u8981Linux\u9700\u8981\u4e24\u79cd\u6587\u4ef6\u7cfb\u7edf<\/p>\n bootfs\u5305\u542b\u6709bootloader\u3002\u7528\u6237\u4ece\u6765\u4e0d\u4f1a\u66f4\u6539bootfs\u3002\u4e8b\u5b9e\u4e0a\uff0c\u5f53\u673a\u5668\u542f\u52a8\u7ed3\u675f\u540e\uff0ckernel\u4f1a\u5378\u8f7d\u6389\u8fd9\u4e2abootfs\u3002<\/p>\n rootfs\u5c31\u662f\u6211\u4eec\u901a\u5e38\u770b\u5230\u4e86Linux\u6587\u4ef6\u76ee\u5f55\uff0c\u5305\u62ec\u00a0\/dev,\u00a0\/proc,\u00a0\/bin,\u00a0\/etc,\/lib,\u00a0\/usr,<\/tt>\u00a0\u548c\/tmp\u7b49\u7b49\u3002\u4e0d\u540c\u7684Linux\u53d1\u884c\u7248\u7684rootfs\u662f\u4e0d\u4e00\u6837\u7684\uff0c\u8f6f\u4ef6\u5305\u7ed3\u6784\u4e5f\u662f\u4e0d\u540c\u7684\u3002Docker\u901a\u8fc7\u7ba1\u7406rootfs\uff0c\u53ef\u4ee5\u5728\u540c\u65f6\u8fd0\u884c\u591a\u4e2aLinux\u53d1\u884c\u7248\u3002<\/tt><\/p>\n \u5f53\u4f20\u7edfLinux\u542f\u52a8\u7684\u65f6\u5019\uff0crootfs\u662f\u53ea\u8bfb\u7684\uff0c\u68c0\u67e5\u5b8c\u6574\u6027\u540e\u4f1a\u8f6c\u5316\u6210\u53ef\u8bfb\u5199\u72b6\u6001\u3002<\/p>\n \u5f53Docker\u6302\u8f7drootfs\u7684\u65f6\u5019\uff0c\u4e5f\u662f\u53ea\u8bfb\u7684\u3002\u4f46\u662f\u4ed6\u5e76\u6ca1\u6709\u628a\u5b83\u8f6c\u5316\u4e3a\u53ef\u8bfb\u5199\u72b6\u6001\uff0c\u800c\u4e14\u5728\u5176\u4e0a\u4f7f\u7528\u00a0union mount<\/a>\u00a0\u6765\u52a0\u4e00\u5c42\uff0c\u521b\u5efa\u4e00\u4e2a\u53ef\u8bfb\u5199\u7684\u6587\u4ef6\u7cfb\u7edf\u3002\u539f\u7406\u7684rootfs\u8fd8\u662f\u53ea\u8bfb\u7684\uff0c\u6570\u636e\u88ab\u5199\u5165\u65b0\u7684\u7a7a\u95f4\u3002Docker\u79f0\u4e4b\u4e3a”\u5c42”\uff0c\u6570\u636e\u53ef\u4ee5\u8fd9\u6837\u4e00\u5c42\u4e00\u5c42\u53e0\u52a0\u8d77\u6765\u3002<\/p>\n \u6700\u521d\u7684\u65f6\u5019\uff0c\u6700\u9876\u5c42\u4e2d\u4ec0\u4e48\u6570\u636e\u4e5f\u6ca1\u6709\uff0c\u5f53\u8fdb\u7a0b\u521b\u5efa\u4fee\u6539\u6587\u4ef6\u7684\u65f6\u5019\uff0c\u6570\u636e\u5c31\u4f1a\u4fdd\u5b58\u5728\u6700\u9876\u5c42\u3002\u5e95\u5c42\u7684\u6587\u4ef6\u7cfb\u7edf\u6ca1\u6709\u4e1d\u6beb\u6539\u53d8\u3002<\/p>\n \u5f53\u5bfc\u51faImage\u7684\u65f6\u5019\uff0c\u5176\u5b9e\u5c31\u662f\u5bfc\u51fa\u6700\u9876\u5c42\u800c\u5df2\u3002<\/p>\n \u7531\u4e8e\u5e95\u5c42\u7684\u53ea\u8bfb\u7684\uff0c\u591a\u4e2aDocker Container\u53ef\u4ee5\u5171\u4eab\uff0c\u63d0\u9ad8\u7684\u6587\u4ef6\u7cfb\u7edf\u7684\u4f7f\u7528\u6548\u7387\u3002<\/p>\n Docker\u662f\u5f00\u6e90\u7684\uff0c\u63d0\u4f9b\u5b8c\u5584\u7684Restful\u63a5\u53e3\uff0c\u8bbe\u8ba1\u7b80\u6d01\uff0c\u76f4\u6233\u75db\u70b9\u3002\u4f46\u662f\u56e0\u6b64\u6bd4\u8f83\u7b80\u5355\uff0c\u6ca1\u6709\u534e\u4e3d\u7684\u529f\u80fd\u3002\u51e4\u6816\u68a7\u6850\uff0c\u4ee5Docker\u4e3a\u6811\u5e72\uff0c\u884d\u751f\u51fa\u8bb8\u591a\u4f18\u79c0\u7684\u9879\u76ee\u3002<\/p>\n\n
PaaS \u7684\u6838\u5fc3\u4ef7\u503c<\/h3>\n
\u9057\u5931\u7684\u65b9\u5411 –\u00a0\u7edd\u5927\u90e8\u5206\u5e94\u7528\u7adf\u7136\u4e0d\u80fd\u65e0\u7f1d\u8fc1\u79fb\u5230\u4e3b\u6d41PaaS\u4e0a<\/h4>\n
PaaS\u8981\u5b9e\u73b0\u5f00\u53d1\u4eba\u548c\u8fd0\u7ef4\u4eba\u7684\u68a6<\/h4>\n
\u5f00\u53d1\u4eba\u7684\u68a6 – \u81ea\u5728\u7684\u8fd0\u884c\u73af\u5883\uff0c\u65e0\u9650\u7684\u8d44\u6e90<\/h5>\n
\u8fd0\u7ef4\u4eba\u7684\u68a6 – \u6ca1\u6709\u6545\u969c\u548c\u91cd\u590d\u7684\u4e8b\uff0c\u51cf\u5c11\u7b49\u5f85<\/h5>\n
Docker\u529f\u80fd<\/h5>\n
\n
PaaS\uff0cIaaS\u672f\u4e1a\u6709\u4e13\u653b<\/h4>\n
\u4f7f\u7528Docker<\/h3>\n
\u5728\u7ebf\u5c1d\u8bd5<\/h4>\n
\u5728Ubuntu\u4e2d\u5b89\u88c5Docker<\/h4>\n
\n
\n
# Add the PPA sources to your apt sources list.\nsudo apt-get install python-software-properties && sudo add-apt-repository ppa:dotcloud\/lxc-docker\n\n# Update your sources\nsudo apt-get update\n\n# Install, you will see another warning that the package cannot be authenticated. Confirm install.\nsudo apt-get install lxc-docker<\/pre>\n
# Add the PPA sources to your apt sources list.\nsudo apt-get install python-software-properties && sudo add-apt-repository ppa:dotcloud\/lxc-docker\n\n# Update your sources\nsudo apt-get update\n\n# Install, you will see another warning that the package cannot be authenticated. Confirm install.\nsudo apt-get install lxc-docker<\/pre>\n
# download the base 'ubuntu' container and run bash inside it while setting up an interactive shell\nsudo docker run -i -t ubuntu \/bin\/bash\n\n# type 'exit' to exit<\/pre>\n
Docker Run\u7684\u65f6\u5019\u53d1\u751f\u4e86\u4ec0\u4e48\uff1f<\/h4>\n
\n
Dock\u8be6\u89e3<\/span><\/h3>\n
\u5728Docker\u4e2d\u8fd0\u884cRedis<\/h4>\n
sudo docker run -i -t ubuntu \/bin\/bash<\/pre>\n
apt-get update\napt-get install redis-server\nexit<\/pre>\n
docker ps -a # grab the container id (this will be the first one in the list)\ndocker commit <container_id> <your username>\/redis<\/pre>\n
sudo docker run -d -p 6379 <your username>\/redis \/usr\/bin\/redis-server<\/pre>\n
sudo docker ps # grab the new container id\nsudo docker inspect <container_id> # grab the ipaddress of the container\nredis-cli -h <ipaddress> -p 6379\nredis 10.0.3.32:6379> set docker awesome\nOK\nredis 10.0.3.32:6379> get docker\n\"awesome\"\nredis 10.0.3.32:6379> exit<\/pre>\n
\u00a0\u6587\u4ef6\u7cfb\u7edf<\/h4>\n
\n
Docker\u751f\u6001\u73af\u5883<\/h3>\n
\n