{"id":15481,"date":"2024-11-18T18:23:11","date_gmt":"2024-11-18T10:23:11","guid":{"rendered":"https:\/\/fwq.ai\/blog\/?p=15481"},"modified":"2024-11-18T18:23:11","modified_gmt":"2024-11-18T10:23:11","slug":"docker%e7%9a%84%e5%ae%9e%e8%b7%b5%e7%ac%94%e8%ae%b0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/15481\/","title":{"rendered":"Docker\u7684\u5b9e\u8df5\u7b14\u8bb0"},"content":{"rendered":"<p>\u5b66Docker\u5dee\u4e0d\u591a\u4e24\u4e2a\u661f\u671f\u4e86\uff0c\u4e3b\u8981\u5b66\u4e60container\u3001image\u3001volume\u3001network\u3001plugin\u3001system\u8fd9\u516d\u4e2a\u90e8\u5206\uff0c\u4eca\u5929\u60f3\u901a\u8fc7\u4ee5\u4e0a\u7684\u5b66\u4e60\uff0c\u5236\u4f5c\u4e00\u4e2acentos + nginx + php7\u7684\u955c\u50cf\u3002<\/p>\n<p>&nbsp;<\/p>\n<h3><strong>1\u3001\u521b\u5efa\u6570\u636e\u5377<\/strong><\/h3>\n<p>\u56e0\u4e3a\u955c\u50cf\u4e00\u65e6\u521b\u5efa\u4e86\uff0c\u955c\u50cf\u7684\u6587\u4ef6\u662f\u4e0d\u80fd\u88ab\u4fee\u6539\u7684\uff08\u672c\u4eba\u4eb2\u6d4b\uff0c\u5982\u679c\u672c\u4eba\u7406\u89e3\u9519\u8bef\uff0c\u8bf7\u6307\u6b63\uff09\uff0c\u6240\u4ee5\u60f3\u628aphp\u548cnginx\u7684\u914d\u7f6e\u3001\u65e5\u5fd7\u3001php\u6587\u4ef6\uff0c\u4ee5\u6570\u636e\u5377\u7684\u5f62\u5f0f\u6302\u8f7d\u5230\u65b0\u521b\u5efa\u7684\u5bb9\u5668\u3002<\/p>\n<pre>docker volume create conf\r\ndocker volume create logs\r\ndocker volume create www<\/pre>\n<h3><strong>2\u3001\u521b\u5efa\u7f51\u7edc<\/strong><\/h3>\n<pre>docker network create --subnet=192.168.30.0\/24 --ip-range=192.168.30.0\/24 br30<\/pre>\n<h3><strong>3\u3001\u4ee5centos\u4e3a\u57fa\u7840\uff0c\u521b\u5efa\u5bb9\u5668php01<\/strong><\/h3>\n<pre>docker create -i --name=php01 --net=br30 --ip=192.168.30.10 --expose={80,443,8080,9000} \r\n-v=conf:\/data\/conf -v=logs:\/data\/logs -v=www:\/data\/www centos:latest<\/pre>\n<h3>4\u3001copy nginx\u548cphp7\u7684\u5b89\u88c5\u5305\u5230\u5bb9\u5668<\/h3>\n<p>\u56e0\u4e3a php01\u5bb9\u5668\u6302\u8f7d\u4e86\u6570\u636e\u5377www\uff0c\u6240\u5728\u6682\u65f6\u5c06\u5b89\u88c5\u5305cp\u5230\u8be5\u76ee\u5f55\u3002libmcrypt\u662fphp\u52a0\u5bc6\u4f9d\u8d56\u5305\u3002<\/p>\n<pre>cp php-7.1.6.tar.gz \/var\/lib\/docker\/volumes\/www\/_data\r\ncp nginx-1.12.0.tar.gz \/var\/lib\/docker\/volumes\/www\/_data\r\ncp libmcrypt-2.5.8.tar.gz \/var\/lib\/docker\/volumes\/www\/_dat<\/pre>\n<h3><strong>5\u3001\u542f\u52a8\u3001\u5e76\u8fdb\u5165\u5bb9\u5668<\/strong><\/h3>\n<pre>docker start php01 &amp;&amp; docker exec -it php01 bash<\/pre>\n<h3>6\u3001\u8bbe\u7f6e\u7f51\u7edc\u4ee3\u7406 \uff0d \u53ef\u7701\u7565<\/h3>\n<p>\u56e0\u4e3a\u672c\u516c\u53f8\u7684\u7f51\u7edc\u9700\u8981\u4f7f\u7528\u4ee3\u7406\uff0c\u624d\u80fd\u94fe\u63a5\u5916\u7f51\u3002<\/p>\n<pre>alias \"la=ll -a\"\r\nalias \"pa=ps aux | grep \"\r\n\r\nhttp_proxy=http:\/\/10.199.75.12:8080\r\nhttps_proxy=http:\/\/10.199.75.12:8080\r\nftp_proxy=http:\/\/10.199.75.12:8080\r\nno_proxy=192.168.80.1,localhost,127.0.0.1,192.168.10.10,192.168.20.10,192.168.30.10\r\nexport http_proxy https_proxy ftp_proxy no_proxy<\/pre>\n<h3>7\u3001\u5728php01\u5bb9\u5668\u7684\/data\/www\u76ee\u5f55\u4e0b\u89e3\u538b\uff0c\u5e76\u5b89\u88c5php7.1.6<\/h3>\n<p>\u53c2\u8003\uff1aphp7\u7684\u5b89\u88c5\u4ee5\u53ca\u7f16\u8bd1\u4e2d\u7684\u9519\u8bef<\/p>\n<h3>8\u3001\u5b89\u88c5Nginx<\/h3>\n<p>\u53c2\u8003\uff1a\u00a0\u00a0Nginx\u7684\u5b89\u88c5\u00a0\u00a0 nginx\u7684\u7f16\u8bd1\u5b89\u88c5\u90e8\u5206<\/p>\n<h3>9\u3001\u79fb\u52a8\u76f8\u5173\u7684\u6587\u4ef6\u5230\/usr\/bin<\/h3>\n<pre># \u5904\u7406php\u4e8c\u8fdb\u5236\u6587\u4ef6\r\ncd \/usr\/local\/php7\/bin\r\nrm -rf phar \r\nmv phar.phar \/usr\/bin\/phar\r\nmv .\/* \/usr\/bin\r\nrm -rf bin\r\n\r\n# \u5904\u7406php-fpm\r\ncd \/usr\/local\/php7\/etc\r\nmv init.d.php-fpm \/usr\/bin\/php-fpm &amp;&amp; chmod 755 \/usr\/bin\/php-fpm\r\n\r\n# \u5904\u7406php\u548cphp-fpm\u914d\u7f6e\u6587\u4ef6 \r\nmv etc \/data\/conf\/php \r\nln -s \/data\/conf\/php\/ etc \r\n\r\n# \u5904\u7406 nginx \r\ncd \/usr\/local\/nginx \r\nmv sbin\/nginx \/usr\/bin\/nginx \r\nrm -rf sbin \r\n\r\nmv conf \/data\/conf\/nginx \r\nln -s \/data\/conf\/nginx conf<\/pre>\n<h3>10\u3001\u8bbe\u7f6ephp\u548cnginx\u7684\u8bbe\u7f6e<\/h3>\n<p>\u4e0b\u8f7d\u5730\u5740\uff1adocker.volume.default.tar.gz<\/p>\n<h3>11\u3001\u6d4b\u8bd5nginx \u548c php-fpm\u662f\u5426\u5b89\u88c5\u6210\u529f<\/h3>\n<pre>php-fpm start\r\nnginx -c \/usr\/local\/nginx\/conf\/nginx.conf\r\ncd \/data\/www &amp;&amp; echo \"&lt;?php phpinfo();\" &gt; index.php<\/pre>\n<h3>12\u3001\u4ece\u5bb9\u5668\u4e2d\u63d0\u4ea4<\/h3>\n<pre>docker commit -m \"centos\u3001php-fpm\u3001php7.1.6\u3001nginx\" php01 binphp:v1<\/pre>\n<p>\u6d4b\u8bd5\uff1a<\/p>\n<pre>docker create -i --net=br30 --ip=192.168.30.20 --name=php02 -v=conf:\/data\/conf \\\r\n-v=logs:\/data\/logs -v=www:\/data\/www binphp:v1\r\n# \u8fdb\u5165\u5bb9\u5668\uff0c\u5e76\u542f\u52a8php-fpm\u548cnginx\r\nphp-fpm start\r\nnginx -c \/usr\/local\/nginx\/conf\/nginx.conf<\/pre>\n<h3>13\u3001\u5bfc\u51fabinphp\u7684\u955c\u50cf\uff0c\u7528\u4e8e\u5728\u5176\u4ed6\u7684\u5bbf\u4e3b\u673a\u4e0a\u4f7f\u7528<\/h3>\n<pre>docker save bindocker | gzip &gt; bindocker.tar.gz<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b66Docker\u5dee\u4e0d\u591a\u4e24\u4e2a\u661f\u671f\u4e86\uff0c\u4e3b\u8981\u5b66\u4e60container\u3001image\u3001volume\u3001network\u3001plugin\u3001system\u8fd9\u516d\u4e2a\u90e8\u5206\uff0c\u4eca\u5929\u60f3\u901a\u8fc7\u4ee5\u4e0a\u7684\u5b66\u4e60\uff0c\u5236\u4f5c\u4e00\u4e2acentos + nginx + php7\u7684\u955c\u50cf\u3002 &nbsp; 1\u3001\u521b\u5efa\u6570\u636e\u5377 \u56e0\u4e3a\u955c\u50cf\u4e00\u65e6\u521b\u5efa\u4e86\uff0c\u955c\u50cf\u7684\u6587\u4ef6\u662f\u4e0d\u80fd\u88ab\u4fee\u6539\u7684\uff08\u672c\u4eba\u4eb2\u6d4b\uff0c\u5982\u679c\u672c\u4eba\u7406\u89e3\u9519\u8bef\uff0c\u8bf7\u6307\u6b63\uff09\uff0c\u6240\u4ee5\u60f3\u628aphp\u548cnginx\u7684\u914d\u7f6e\u3001\u65e5\u5fd7\u3001php\u6587\u4ef6\uff0c\u4ee5\u6570\u636e\u5377\u7684\u5f62\u5f0f\u6302\u8f7d\u5230\u65b0\u521b\u5efa\u7684\u5bb9\u5668\u3002 docker volume create conf docker volume create logs docker volume create www 2\u3001\u521b\u5efa\u7f51\u7edc docker network create &#8211;subnet=192.168.30.0\/24 &#8211;ip-range=192.168.30.0\/24 br30 3\u3001\u4ee5centos\u4e3a\u57fa\u7840\uff0c\u521b\u5efa\u5bb9\u5668php01 docker create -i &#8211;name=php01 &#8211;net=br30 &#8211;ip=192.168.30.10 &#8211;expose={80,443,8080,9000} -v=conf:\/data\/conf -v=logs:\/data\/logs -v=www:\/data\/www centos:latest 4\u3001copy nginx\u548cphp7\u7684\u5b89\u88c5\u5305\u5230\u5bb9\u5668 \u56e0\u4e3a php01\u5bb9\u5668\u6302\u8f7d\u4e86\u6570\u636e\u5377www\uff0c\u6240\u5728\u6682\u65f6\u5c06\u5b89\u88c5\u5305cp\u5230\u8be5\u76ee\u5f55\u3002libmcrypt\u662fphp\u52a0\u5bc6\u4f9d\u8d56\u5305\u3002 cp php-7.1.6.tar.gz \/var\/lib\/docker\/volumes\/www\/_data cp nginx-1.12.0.tar.gz \/var\/lib\/docker\/volumes\/www\/_data cp libmcrypt-2.5.8.tar.gz \/var\/lib\/docker\/volumes\/www\/_dat 5\u3001\u542f\u52a8\u3001\u5e76\u8fdb\u5165\u5bb9\u5668 docker start [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-15481","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=15481"}],"version-history":[{"count":1,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15481\/revisions"}],"predecessor-version":[{"id":15482,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15481\/revisions\/15482"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=15481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=15481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=15481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}