{"id":1404,"date":"2024-09-08T20:37:17","date_gmt":"2024-09-08T12:37:17","guid":{"rendered":"http:\/\/blue.yn.cn\/?p=1404"},"modified":"2024-12-24T11:28:48","modified_gmt":"2024-12-24T03:28:48","slug":"docker%e6%95%b0%e6%8d%ae%e7%ae%a1%e7%90%86","status":"publish","type":"post","link":"http:\/\/blue.yn.cn\/?p=1404","title":{"rendered":"docker\u6570\u636e\u7ba1\u7406"},"content":{"rendered":"<h3>\u6570\u636e\u6301\u4e45\u5316\u4ecb\u7ecd<\/h3>\n<h4>\u4e3a\u4f55\u9700\u8981\u5377<\/h4>\n<p>\u5728\u542f\u52a8\u5bb9\u5668\u65f6\uff0c<code>docker<\/code>\u4f1a\u52a0\u8f7d\u5bf9\u5e94\u7684\u53ea\u8bfb\u955c\u50cf\u5c42\uff0c\u5e76\u5728\u9876\u90e8\u6dfb\u52a0\u4e00\u4e2a\u8bfb\u5199\u5c42\u3002<br \/>\n\u5728\u5bb9\u5668\u8fd0\u884c\u8fc7\u7a0b\u4e2d\uff0c\u6240\u6709\u6570\u636e\u7684\u5b58\u50a8\u4ee5\u53ca\u6587\u4ef6\u7684\u4fee\u6539\u90fd\u53d1\u751f\u5728\u8fd9\u4e2a\u8bfb\u5199\u5c42\u3002<\/p>\n<p>\u5f53\u9700\u8981\u4fee\u6539\u4e00\u4e2a\u5df2\u5b58\u5728\u7684\u6587\u4ef6\u65f6\uff0c<code>docker<\/code>\u4f1a\u91c7\u7528\u5199\u65f6\u590d\u5236\u673a\u5236\uff08<code>copy-on-write<\/code>\uff0c\u7b80\u79f0<code>cow<\/code>\uff09\uff0c<strong>\u5c06\u6587\u4ef6\u4ece\u53ea\u8bfb\u5c42\u590d\u5236\u5230\u8bfb\u5199\u5c42\u5e76\u8fdb\u884c\u4fee\u6539\uff0c\u540c\u65f6\u4fdd\u7559\u53ea\u8bfb\u5c42\u4e2d\u7684\u539f\u59cb\u6587\u4ef6<\/strong>\u3002<br \/>\n\u539f\u59cb\u6587\u4ef6\u5176\u5b9e\u4e0d\u4f1a\u88ab\u4fee\u6539\uff0c\u53ea\u662f\u5728\u8bfb\u5199\u5c42\u4e2d\u7684\u526f\u672c\u4f1a\u5c06\u5176\u539f\u59cb\u6587\u4ef6\u8986\u76d6\u3002<\/p>\n<p>\u5728\u8fd0\u884c\u4e00\u4e2a\u5bf9<code>io<\/code>\u6027\u80fd\u8981\u6c42\u8f83\u9ad8\u7684\u5e94\u7528\uff0c\u5982<code>mysql<\/code>\u6570\u636e\u5e93\u65f6\uff0c<code>cow<\/code>\u673a\u5236\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6027\u80fd\u4e0b\u964d\u3002\u4e3b\u8981\u67092\u4e2a\u539f\u56e0\uff1a<\/p>\n<ul>\n<li>1.\u5199\u65f6\u590d\u5236\uff08<code>cow<\/code>\uff09\u673a\u5236\uff1a\u5f53\u9700\u8981\u4fee\u6539\u4e00\u4e2a\u5df2\u5b58\u5728\u7684\u6587\u4ef6\u65f6\uff0c\u8be5\u6587\u4ef6\u4f1a\u4ece\u53ea\u8bfb\u5c42\u590d\u5236\u5230\u8bfb\u5199\u5c42\u3002\u5bf9\u4e8e\u9891\u7e41\u4fee\u6539\u6587\u4ef6\u7684\u5e94\u7528\uff0c\u8fd9\u6837\u7684\u64cd\u4f5c\u53ef\u80fd\u4f1a\u4ea7\u751f\u8f83\u5927\u7684<code>i\/o<\/code>\u5f00\u9500\u3002<\/li>\n<li>2.\u5c42\u53e0\u6587\u4ef6\u7cfb\u7edf\uff1a<code>docker<\/code>\u955c\u50cf\u662f\u7531\u591a\u4e2a\u53ea\u8bfb\u5c42\u53e0\u52a0\u800c\u6210\u7684\uff0c\u8fd9\u610f\u5473\u7740\u5728\u67e5\u627e\u6587\u4ef6\u65f6\uff0c<code>docker<\/code>\u9700\u8981\u5728\u6bcf\u4e00\u5c42\u9010\u5c42\u67e5\u627e\u3002\u5bf9\u4e8e\u9700\u8981\u9891\u7e41\u8bfb\u53d6\u6587\u4ef6\u7684\u5e94\u7528\uff0c\u8fd9\u79cd\u65b9\u5f0f\u4f1a\u589e\u52a0\u6587\u4ef6\u67e5\u627e\u7684\u65f6\u95f4\u3002<\/li>\n<\/ul>\n<h4>\u4ec0\u4e48\u662f\u6570\u636e\u5377<\/h4>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c<code>docker<\/code>\u5f15\u5165\u4e86\u5377\uff08<code>volume<\/code>\uff09\u7684\u6982\u5ff5\u3002<br \/>\n\u901a\u8fc7\u4f7f\u7528\u5377\uff0c\u53ef\u4ee5\u5c06<em>\u5bb9\u5668\u79cd\u8981\u5b58\u50a8\u6570\u636e\u7684\u76ee\u5f55<\/em>\u4e0e<em>\u5bbf\u4e3b\u673a\u7684\u67d0\u4e2a\u76ee\u5f55<\/em>\u8fdb\u884c\u7ed1\u5b9a\u3002<br \/>\n\u800c\u4e0d\u5c06\u6570\u636e\u5b58\u50a8\u81f3\u5bb9\u5668\u7684\u8bfb\u5199\u5c42\uff0c\u56e0\u6b64\uff0c\u5377\u662f\u4e00\u79cd\u53ef\u4ee5\u7ed5\u8fc7\u8054\u5408\u6587\u4ef6\u7cfb\u7edf\uff0c\u5b9e\u73b0\u5bb9\u5668\u6570\u636e\u7684\u6301\u4e45\u5316\u65b9\u5f0f\u3002<br \/>\n\u8fd9\u6837\uff0c\u5373\u4f7f\u5bb9\u5668\u88ab\u5220\u9664\u6216\u91cd\u65b0\u6784\u5efa\uff0c\u6570\u636e\u5377\u4e2d\u7684\u6570\u636e\u4e5f\u53ef\u4ee5\u88ab\u4fdd\u7559\u4e0b\u6765\u3002<\/p>\n<p>\u540c\u65f6\u5377\u53ef\u4ee5\u63d0\u9ad8<code>i\/o<\/code>\u6027\u80fd\uff0c\u56e0\u4e3a\u5b83\u76f4\u63a5\u5728\u4e3b\u673a\u7684\u6587\u4ef6\u7cfb\u7edf\u4e0a\u64cd\u4f5c\uff0c\u4e0d\u9700\u8981\u901a\u8fc7\u5bb9\u5668\u7684\u5b58\u50a8\u5f15\u64ce\u3002<br \/>\n\u8fd9\u5bf9\u4e8e\u5bf9<code>i\/o<\/code>\u6027\u80fd\u6709\u8981\u6c42\u7684\u5e94\u7528\uff0c\u5982<code>mysql<\/code>\u6570\u636e\u5e93\uff0c\u662f\u975e\u5e38\u6709\u76ca\u7684\u3002<\/p>\n<h4>\u6570\u636e\u5377\u7c7b\u578b<\/h4>\n<p><code>docker<\/code>\u6709\u4e24\u79cd\u7c7b\u578b\u7684\u5377\uff0c\u6bcf\u79cd\u7c7b\u578b\u90fd\u5728\u5bb9\u5668\u4e2d\u5b58\u5728\u4e00\u4e2a\u6302\u8f7d\u70b9\uff0c\u4f46\u5176\u5728\u5bbf\u4e3b\u673a\u4e0a\u7684\u4f4d\u7f6e\u6709\u6240\u4e0d\u540c\uff1a<\/p>\n<ul>\n<li><code>volumes<\/code>\uff1a\u8be5\u5377\u7531<code>docker<\/code>\u81ea\u884c\u7ba1\u7406\u7684\u6570\u636e\u5377\uff0c\u901a\u5e38\u5728<code>\/var\/lib\/docker\/volumes<\/code>\u76ee\u5f55\u4e0b(\u5b58\u50a8\u4f4d\u7f6e\u4e4b\u524d\u5df2\u6539\u4e3a<code>\/data\/docker\/volumes<\/code>)<\/li>\n<li><code>bind mounting<\/code>\uff1a\u8fd9\u79cd\u7c7b\u578b\u7684\u6570\u636e\u5377\u5141\u8bb8\u76f4\u63a5\u5c06\u4e3b\u673a\u7cfb\u7edf\u4e0a\u7684\u76ee\u5f55\u8def\u5f84\u7ed1\u5b9a\u5230\u5bb9\u5668\u4e2d\u3002<\/li>\n<li><code>tmpfs<\/code>\uff1a\u6302\u8f7d\u4ec5\u5b58\u50a8\u5728\u4e3b\u673a\u7cfb\u7edf\u7684\u5185\u5b58\u4e2d\uff0c\u5e76\u4e14\u4e0d\u4f1a\u5199\u5165\u4e3b\u673a\u7cfb\u7edf\u7684\u6587\u4ef6\u7cfb\u7edf\u4e2d\u3002\uff08\u4e34\u65f6\u5b58\u50a8\uff09<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/09\/image-1726017477106.png\" alt=\"file\" \/><\/p>\n<h3>\u6570\u636e\u6301\u4e45\u5316-datavolume<\/h3>\n<ul>\n<li>\u8fd0\u884c\u4e00\u4e2a<code>mysql:8.0<\/code>\u7684\u955c\u50cf<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">docker run -d --name mysql1 -v \/var\/lib\/mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=true mysql:8.0\nf639688cd25734cd41dcee582cb633886caa33b9545a8f83fd744bcdfa09808a\n\ndocker ps\nCONTAINER ID   IMAGE                     COMMAND                   CREATED         STATUS         PORTS                                         NAMES\nf639688cd257   mysql:8.0                 &quot;docker-entrypoint.s\u2026&quot;   5 seconds ago   Up 4 seconds   3306\/tcp, 33060\/tcp                           mysql1<\/code><\/pre>\n<ul>\n<li>\u76d1\u6d4b<code>mysql<\/code>\u6570\u636e\u6301\u4e45\u5316<br \/>\n1.\u68c0\u67e5\u8be5\u955c\u50cf\u542f\u52a8\u7684\u5bb9\u5668\u5c06<code>\/var\/lib\/mysql<\/code>\u76ee\u5f55\u6301\u4e45\u5316\u81f3\u672c\u5730\u54ea\u4e2a\u8def\u5f84<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">docker volume ls\nDRIVER    VOLUME NAME\nlocal     aba5457442eff265ee7939c401df6cdcd949d9fe81a5aad91172ca2d2bb61d38<\/code><\/pre>\n<p>2.\u901a\u8fc7<code>inspect<\/code>\u67e5\u770b\u8be6\u60c5\uff0c\u83b7\u53d6<code>mount<\/code>\u4fe1\u606f<\/p>\n<pre><code class=\"language-bash\">docker volume inspect aba5457442eff265ee7939c401df6cdcd949d9fe81a5aad91172ca2d2bb61d38\n[\n    {\n        &quot;CreatedAt&quot;: &quot;2024-09-11T09:24:09+08:00&quot;,\n        &quot;Driver&quot;: &quot;local&quot;,\n        &quot;Labels&quot;: {\n            &quot;com.docker.volume.anonymous&quot;: &quot;&quot;\n        },\n        &quot;Mountpoint&quot;: &quot;\/data\/docker\/volumes\/aba5457442eff265ee7939c401df6cdcd949d9fe81a5aad91172ca2d2bb61d38\/_data&quot;,\n        &quot;Name&quot;: &quot;aba5457442eff265ee7939c401df6cdcd949d9fe81a5aad91172ca2d2bb61d38&quot;,\n        &quot;Options&quot;: null,\n        &quot;Scope&quot;: &quot;local&quot;\n    }\n]<\/code><\/pre>\n<p>3.\u68c0\u67e5\u6302\u8f7d\u70b9\u6570\u636e<\/p>\n<pre><code class=\"language-bash\">ls \/data\/docker\/volumes\/aba5457442eff265ee7939c401df6cdcd949d9fe81a5aad91172ca2d2bb61d38\/_data\/\nauto.cnf       binlog.index  client-cert.pem    #ib_16384_1.dblwr  ibtmp1        mysql       performance_schema  server-cert.pem  undo_001\nbinlog.000001  ca-key.pem    client-key.pem     ib_buffer_pool     #innodb_redo  mysql.ibd   private_key.pem     server-key.pem   undo_002\nbinlog.000002  ca.pem        #ib_16384_0.dblwr  ibdata1            #innodb_temp  mysql.sock  public_key.pem      sys<\/code><\/pre>\n<p>4.\u7531\u4e8e\u524d\u9762\u521b\u5efa\u5bb9\u5668\u6ca1\u6709\u7ed9<code>volume<\/code>\u5b9a\u4e49\u540d\u79f0\uff0c\u8fd9\u6837\u5f88\u96be\u786e\u8ba4\u662f\u54ea\u4e2a\u5bb9\u5668\u4ea7\u751f\u7684\u6570\u636e\uff0c\u53ef\u4ee5\u5728<code>docker run<\/code>\u65f6\u901a\u8fc7<code>-v<\/code>\u6dfb\u52a0\u522b\u540d\u3002<br \/>\n<code>-v<\/code> \u522b\u540d\uff1a\u5bb9\u5668\u9700\u6301\u4e45\u5316\u76ee\u5f55<\/p>\n<pre><code class=\"language-bash\">docker run -d --name mysql2 -v mysql_data:\/var\/lib\/mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=true mysql:8.0\ndd855bff2380393d0965c4306c8b42bfb869766bf5509e4e85571cb823994906\n\ndocker volume ls\nDRIVER    VOLUME NAME\nlocal     aba5457442eff265ee7939c401df6cdcd949d9fe81a5aad91172ca2d2bb61d38\nlocal     mysql_data\n\ndocker volume inspect mysql_data\n[\n    {\n        &quot;CreatedAt&quot;: &quot;2024-09-11T09:42:04+08:00&quot;,\n        &quot;Driver&quot;: &quot;local&quot;,\n        &quot;Labels&quot;: null,\n        &quot;Mountpoint&quot;: &quot;\/data\/docker\/volumes\/mysql_data\/_data&quot;,\n        &quot;Name&quot;: &quot;mysql_data&quot;,\n        &quot;Options&quot;: null,\n        &quot;Scope&quot;: &quot;local&quot;\n    }\n]<\/code><\/pre>\n<h4>\u9a8c\u8bc1mysql\u6570\u636e\u6301\u4e45\u5316<\/h4>\n<p>\u9a8c\u8bc1\u6570\u636e\u7684\u6301\u4e45\u5316\u662f\u5426\u6709\u5bf9\u5e94\u7684\u6570\u636e\uff1a<\/p>\n<ul>\n<li>\n<p>1.\u5728<code>mysql2<\/code>\u5bb9\u5668\u4e2d\u521b\u5efa\u4e00\u4e2a<code>db<\/code>\u7684\u6570\u636e\u5e93\uff0c\u7136\u540e\u5f3a\u5236\u5e72\u6389<code>mysql2<\/code>\u5bb9\u5668<\/p>\n<\/li>\n<li>\n<p>2.\u542f\u52a8<code>mysql3<\/code>\u5bb9\u5668\uff0c\u7136\u540e\u4f7f\u7528<code>mysql2<\/code>\u5bb9\u5668\u6301\u4e45\u5316\u4e0b\u6765\u7684\u6570\u636e<\/p>\n<\/li>\n<li>\n<p>3.\u767b\u5f55<code>mysql3<\/code>\u5bb9\u5668\uff0c\u68c0\u67e5<code>mysql<\/code>\u6570\u636e\u5e93\u7684\u6570\u636e\uff0c\u662f\u5426\u4e0e\u539f<code>mysql2<\/code>\u5bb9\u5668\u591f\u4e00\u81f4<\/p>\n<\/li>\n<li>\n<p>\u767b\u5f55<code>mysql<\/code>\u6570\u636e\u5e93\uff0c\u7136\u540e\u521b\u5efa\u4e00\u4e2a<code>hello<\/code>\u7684\u5e93\uff0c\u9000\u51fa\u540e\u5f3a\u5236\u5220\u9664\u6389<code>mysql2<\/code>\u5bb9\u5668<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">docker exec -it mysql2 \/bin\/bash\nbash-5.1# mysql\nmysql&gt; create database hello;\nQuery OK, 1 row affected (0.02 sec)\nmysql&gt; show databases;\n+--------------------+\n| Database           |\n+--------------------+\n| hello              |\n| information_schema |\n| mysql              |\n| performance_schema |\n| sys                |\n+--------------------+\n5 rows in set (0.00 sec)<\/code><\/pre>\n<ul>\n<li>\u505c\u6b62\u5220\u9664<code>mysql2<\/code>\u8fd9\u4e2a\u5bb9\u5668<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">docker stop mysql2\ndocker rm mysql2<\/code><\/pre>\n<ul>\n<li>\u542f\u52a8<code>mysql3<\/code>\u5bb9\u5668\uff0c\u7136\u540e\u4f7f\u7528<code>mysql2<\/code>\u5bb9\u5668\u6301\u4e45\u5316\u4e0b\u6765\u7684\u6570\u636e<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">docker run -d --name mysql3 -v mysql_data:\/var\/lib\/mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=true mysql:8.0\n84d77bdab95ed937b5875f68258634c42f6a8a160302e35d44d028eaa15618e2<\/code><\/pre>\n<ul>\n<li>\u767b\u5f55<code>mysql3<\/code>\u5bb9\u5668\uff0c\u68c0\u67e5<code>mysql<\/code>\u6570\u636e\u5e93\u7684\u6570\u636e\uff0c\u662f\u5426\u4e0e\u539f<code>mysql2<\/code>\u5bb9\u5668\u6570\u636e\u4e00\u81f4<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">docker exec -it mysql3 \/bin\/bash\nbash-5.1# mysql\nmysql&gt; show databases;\n+--------------------+\n| Database           |\n+--------------------+\n| hello              |\n| information_schema |\n| mysql              |\n| performance_schema |\n| sys                |\n+--------------------+\n5 rows in set (0.00 sec)<\/code><\/pre>\n<h3>\u6570\u636e\u6302\u8f7d-bindmounting<\/h3>\n<h4>bindmount\u573a\u666f\u8bf4\u660e<\/h4>\n<p>\u5728<code>docker<\/code>\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>bindmount<\/code>\u7684\u65b9\u5f0f\u5c06\u5bbf\u4e3b\u673a\u4e0a\u7684\u76ee\u5f55\u6216\u6587\u4ef6\u6302\u8f7d\u5230\u5bb9\u5668\u4e2d\uff0c\u5b9e\u73b0\u6570\u636e\u5171\u4eab\u548c\u6301\u4e45\u5316\u5b58\u50a8\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5728\u90e8\u7f72\u9759\u6001\u7f51\u7ad9\u65f6\uff0c\u53ef\u4ee5\u5c06\u5bbf\u4e3b\u673a\u4e2d\u5b58\u653e\u9759\u6001\u7f51\u9875\u6587\u4ef6\u7684<code>\/html\/<\/code>\u76ee\u5f55\u7ed1\u5b9a\u5230<code>nginx<\/code>\u5bb9\u5668\u4e2d\u7684<code>\/usr\/share\/nginx\/html<\/code>\u76ee\u5f55\u3002<br \/>\n\u8fd9\u6837\u5373\u4f7f\u5bb9\u5668\u88ab\u5220\u9664\uff0c\u9759\u6001\u7f51\u7ad9\u7684\u6587\u4ef6\u4e5f\u4e0d\u4f1a\u4e22\u5931\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u6587\u4ef6\u5b9e\u9645\u4e0a\u5b58\u50a8\u5728\u5bbf\u4e3b\u673a\u4e0a\uff0c\u5e76\u901a\u8fc7<code>bind mounting<\/code>\u7684\u65b9\u5f0f\u6302\u8f7d\u5230\u5bb9\u5668\u4e2d\u3002<\/p>\n<p>\u4e0e\u6570\u636e\u5377\u4e0d\u540c\u7684\u662f\uff0c<code>bind mounting<\/code>\u4e0d\u9700\u8981\u5728\u5bb9\u5668\u521b\u5efa\u65f6\u5c31\u5b9a\u4e49\u6570\u636e\u5377\uff0c\u800c\u662f\u5728\u542f\u52a8\u5bb9\u5668\u65f6\u52a8\u6001\u5730\u5c06\u5bbf\u4e3b\u673a\u4e2d\u7684\u76ee\u5f55\u6216\u6587\u4ef6\u7ed1\u5b9a\u5230\u5bb9\u5668\u4e2d\uff0c\u8fd9\u79cd\u65b9\u5f0f\u66f4\u52a0\u7075\u6d3b\u3002<\/p>\n<h4>\u51c6\u5907\u7ad9\u70b9\u4ee3\u7801<\/h4>\n<pre><code class=\"language-bash\">mkdir \/html\necho &quot;hello,bind mounting&quot; &gt; \/html\/index.html<\/code><\/pre>\n<h4>\u8fd0\u884cnginx\u5bb9\u5668<\/h4>\n<p>\u542f\u52a8\u4e00\u4e2a<code>nginx<\/code>\u5bb9\u5668\uff0c<\/p>\n<pre><code class=\"language-bash\">docker run -d -P nginx\ndocker ps\nCONTAINER ID   IMAGE                     COMMAND                   CREATED         STATUS         PORTS                                         NAMES\nb589bcb118d2   nginx                     &quot;\/docker-entrypoint.\u2026&quot;   9 seconds ago   Up 8 seconds   0.0.0.0:32769-&gt;80\/tcp, :::32769-&gt;80\/tcp       quizzical_wiles\n\n curl localhost:32769\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;Welcome to nginx!&lt;\/title&gt;\n&lt;style&gt;\nhtml { color-scheme: light dark; }\nbody { width: 35em; margin: 0 auto;\nfont-family: Tahoma, Verdana, Arial, sans-serif; }\n&lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;h1&gt;Welcome to nginx!&lt;\/h1&gt;\n&lt;p&gt;If you see this page, the nginx web server is successfully installed and\nworking. Further configuration is required.&lt;\/p&gt;\n\n&lt;p&gt;For online documentation and support please refer to\n&lt;a href=&quot;http:\/\/nginx.org\/&quot;&gt;nginx.org&lt;\/a&gt;.&lt;br\/&gt;\nCommercial support is available at\n&lt;a href=&quot;http:\/\/nginx.com\/&quot;&gt;nginx.com&lt;\/a&gt;.&lt;\/p&gt;\n\n&lt;p&gt;&lt;em&gt;Thank you for using nginx.&lt;\/em&gt;&lt;\/p&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<p>\u505c\u6b62\u5220\u9664\u5bb9\u5668\uff0c\u7136\u540e\u518d\u542f\u52a8\uff0c\u7136\u540e\u5c06\u672c\u5730\u7684<code>\/html<\/code>\u76ee\u5f55\u6302\u8f7d\u81f3\u5bb9\u5668\u7684<code>\/usr\/share\/nginx\/html<\/code><\/p>\n<pre><code class=\"language-bash\">docker stop b589\ndocker rm b589\n\ndocker run -d -P -v \/html\/:\/usr\/share\/nginx\/html nginx\nc074ec65f34dd34c4a0c3141ad5d99e4001bcab65149d95a7971c1cf7d2261ae<\/code><\/pre>\n<h4>\u68c0\u67e5\u5bb9\u5668\u6302\u8f7d\u7ed3\u679c<\/h4>\n<ol>\n<li>\u8bbf\u95ee\u5bbf\u4e3b\u673a\u768432770\u7aef\u53e3\uff0c<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">curl localhost:32770\nhello,bind mounting<\/code><\/pre>\n<ol start=\"2\">\n<li>\u4fee\u6539<code>\/html<\/code>\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\uff0c\u68c0\u67e5\u5bb9\u5668\u4e2d\u7684<code>nginx<\/code>\u662f\u5426\u8fd4\u56de\u65b0\u7684\u5185\u5bb9<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">echo &quot;hello docker&quot; &gt;&gt; \/html\/index.html\ncurl localhost:32770\nhello,bind mounting\nhello docker\n\ndocker inspect c074\n &quot;Mounts&quot;: [\n            {\n                &quot;Type&quot;: &quot;bind&quot;,\n                &quot;Source&quot;: &quot;\/html&quot;,\n                &quot;Destination&quot;: &quot;\/usr\/share\/nginx\/html&quot;,\n                &quot;Mode&quot;: &quot;&quot;,\n                &quot;RW&quot;: true,\n                &quot;Propagation&quot;: &quot;rprivate&quot;\n            }\n        ],<\/code><\/pre>\n<p>\u5f53\u6211\u4eec\u5728\u672c\u5730\u5f00\u53d1\u9879\u76ee\uff0c\u901a\u8fc7<code>docker<\/code>\u8fd0\u884c\u65f6\uff0c\u4ec5\u9700\u8981\u5c06\u9879\u76ee\u4ee3\u7801\u6302\u8f7d\u81f3\u5bb9\u5668\u4e2d\uff0c\u5f53\u9879\u76ee\u5185\u5bb9\u53d1\u751f\u6539\u53d8\uff0c\u5bb9\u5668\u5c31\u53ef\u4ee5\u7acb\u9a6c\u770b\u5230\u53d8\u5316\u3002<\/p>\n<h4>\u5355\u5bb9\u5668\u591a\u8def\u5f84\u6302\u8f7d\u5b9e\u8df5<\/h4>\n<p>\u5f53\u6211\u4eec\u9700\u8981\u4f7f\u7528\u5355\u4e2a<code>nginx<\/code>\u5bb9\u5668\u8d56\u63d0\u4f9b\u591a\u4e2a\u865a\u62df\u673a\u670d\u52a1\uff0c\u5176\u4e2d\u6bcf\u4e2a\u865a\u62df\u673a\u4e3b\u673a\u670d\u52a1\u90fd\u6709\u81ea\u5df1\u7684\u7f51\u7ad9\u5185\u5bb9\u548c\u7aef\u53e3\u3002<br \/>\n\u5177\u4f53\u6765\u8bf4\uff0c\u6211\u4eec\u9700\u8981\u5b9e\u73b0\u4ee5\u4e0b\u4e24\u4e2a\u865a\u62df\u4e3b\u673a\u7ad9\u70b9\uff1a<\/p>\n<ul>\n<li>\u865a\u62df\u7ad9\u70b91\uff1a\u76d1\u542c80\u7aef\u53e3\uff0c\u8bfb\u53d6<code>\/var\/www\/code1\/index.html<\/code>\uff0c\u8fd4\u56de\u81ea\u5b9a\u4e49\u7684\u7f51\u7ad9\u5185\u5bb9<code>hello nginx 80<\/code><\/li>\n<li>\u865a\u62df\u7ad9\u70b92\uff1a\u76d1\u542c81\u7aef\u53e3\uff0c\u8bfb\u53d6<code>\/var\/www\/code2\/index.html<\/code>\uff0c\u8fd4\u56de\u81ea\u5b9a\u4e49\u7684\u7f51\u7ad9\u5185\u5bb9<code>hello nginx 81<\/code><\/li>\n<\/ul>\n<p>\u601d\u8def\uff1a\u5728\u5bbf\u4e3b\u673a\u4e0a\u521b\u5efa\u4e24\u4e2a\u7f51\u7ad9\u76ee\u5f55\uff0c\u7136\u540e\u901a\u8fc7\u5bbf\u4e3b\u673a\u6302\u8f7d\u81f3\u865a\u62df\u673a\u5bf9\u5e94\u7684\u76ee\u5f55\uff0c\u540c\u65f6\u9700\u8981\u51c6\u5907<code>nginx.conf<\/code>\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<ul>\n<li>\u5bbf\u4e3b\u673a\u76ee\u5f551\uff1a<code>\/html\/code1\/index.html<\/code>--&gt; \u6302\u8f7d\u5bb9\u5668 --&gt; <code>\/var\/www\/code1\/index.html<\/code><\/li>\n<li>\u5bbf\u4e3b\u673a\u76ee\u5f552\uff1a<code>\/html\/code2\/index.html<\/code>--&gt; \u6302\u8f7d\u5bb9\u5668 --&gt; <code>\/var\/www\/code2\/index.html<\/code><\/li>\n<\/ul>\n<ol>\n<li>\u51c6\u5907<code>nginx.conf<\/code>\u914d\u7f6e\u6587\u4ef6<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">cat \/html\/nginx.conf\nuser nginx;\nworker_processes 1;\n\nerror_log \/var\/log\/nginx\/error.log warn;\npid \/var\/run\/nginx.pid;\n\nevents {\n worker_connections 1024;\n}\n\nhttp {\n        include \/etc\/nginx\/mime.types;\n        default_type application\/octet-stream;\n        log_format main &#039;$remote_addr - $remote_user [$time_local] &quot;$request&quot; &#039;\n                        &#039;$status $body_bytes_sent &quot;$http_referer&quot; &#039;\n                        &#039;&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;&#039;;\n        access_log \/var\/log\/nginx\/access.log main;\n\nserver {\n        listen 80;\n        server_name _;\n        location \/ {\n                root \/var\/www\/code1;\n        index index.html;\n        }\n}\n\nserver {\n        listen 81;\n        server_name _;\n        location \/ {\n                root \/var\/www\/code2;\n                index index.html;\n        }\n  }\n}<\/code><\/pre>\n<ol start=\"2\">\n<li>\u5728\u5bbf\u4e3b\u673a\u4e0a\u51c6\u5907\u5bf9\u5e94\u7ad9\u70b9\u7684\u9759\u6001\u8d44\u6e90\u6587\u4ef6<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">mkdir \/html\/code1\nmkdir \/html\/code2\necho &quot;hello nginx 80&quot; &gt; \/html\/code1\/index.html\necho &quot;hello nginx 81&quot; &gt; \/html\/code2\/index.html<\/code><\/pre>\n<ol start=\"3\">\n<li>\u8fd0\u884c<code>nginx<\/code>\u5bb9\u5668\uff0c\u800c\u540e\u6302\u8f7d\u76f8\u5e94\u7684\u6570\u636e\u81f3\u5bb9\u5668\u4e2d\uff1b<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">docker run -d -p 8880:80 -p 8881:81 \\\n-v \/html\/nginx.conf:\/etc\/nginx\/nginx.conf \\\n-v \/html\/code1:\/var\/www\/code1 \\\n-v \/html\/code2:\/var\/www\/code2 \\\nnginx<\/code><\/pre>\n<ol start=\"4\">\n<li>\u8bbf\u95ee\u5bf9\u5e94\u7aef\u53e3\u9a8c\u8bc1\u7ed3\u679c<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">curl  localhost:8880\nhello nginx 80\ncurl  localhost:8881\nhello nginx 81<\/code><\/pre>\n<h3>\u5b9e\u8df5\u6848\u4f8b<\/h3>\n<h4>\u9700\u6c42\u63cf\u8ff0<\/h4>\n<p>\u5b9e\u73b0\uff1a<code>wordpress<\/code>\u5e94\u7528\uff08<code>wordpress<\/code>\u955c\u50cf+<code>mysql<\/code>\u955c\u50cf\uff09<\/p>\n<ol>\n<li>\u8fd0\u884c\u4e00\u4e2a<code>mysql<\/code>\u955c\u50cf\uff0c\u9700\u8981\u6301\u4e45\u5316\u6570\u636e\u5230\u672c\u5730\uff0c\u4f7f\u7528<code>volumes<\/code>\u5377\u7c7b\u578b\uff1b<\/li>\n<li>\u8fd0\u884c\u4e00\u4e2a<code>wordpress<\/code>\u955c\u50cf\uff0c\u9700\u8981\u4f20\u9012\u73af\u5883\u53d8\u91cf\u53bb\u8fde\u63a5<code>mysql<\/code>\uff1b<\/li>\n<li><code>wordpress<\/code>\u9700\u8981\u66b4\u973280\u7aef\u53e3\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\uff1b<\/li>\n<li><code>wordpress<\/code>\u662f\u53ef\u4ee5\u4e0a\u4f20\u56fe\u7247\uff0c\u9700\u8981\u6301\u4e45\u5316\u5230\u672c\u5730\uff08<code>bindmounting<\/code>\u65b9\u5f0f\uff09\uff1b<\/li>\n<\/ol>\n<h4>mysql<\/h4>\n<ol>\n<li>\u8fd0\u884c<code>mysql<\/code><\/li>\n<\/ol>\n<pre><code class=\"language-bash\">docker run -d --name db \\\n-v mysql_data:\/var\/lib\/mysql \\\n-e &quot;MYSQL_ROOT_PASSWORD=123456&quot; \\\n-e &quot;MYSQL_DATABASE=wordpress&quot; \\\nmysql<\/code><\/pre>\n<ol start=\"2\">\n<li>\u9a8c\u8bc1<code>mysql<\/code>\u53ef\u7528\u6027<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">docker inspect db\n        &quot;Mounts&quot;: [\n            {\n                &quot;Type&quot;: &quot;volume&quot;,\n                &quot;Name&quot;: &quot;mysql_data&quot;,\n                &quot;Source&quot;: &quot;\/data\/docker\/volumes\/mysql_data\/_data&quot;,\n                &quot;Destination&quot;: &quot;\/var\/lib\/mysql&quot;,\n                &quot;Driver&quot;: &quot;local&quot;,\n                &quot;Mode&quot;: &quot;z&quot;,\n                &quot;RW&quot;: true,\n                &quot;Propagation&quot;: &quot;&quot;\n            }\n        ],\n\ndocker exec -it db \/usr\/bin\nbash-5.1# mysql -uroot -p123456\nmysql&gt; show databases;\n+--------------------+\n| Database           |\n+--------------------+\n| information_schema |\n| mysql              |\n| performance_schema |\n| sys                |\n| wordpress          |\n+--------------------+\n5 rows in set (0.04 sec)<\/code><\/pre>\n<h4>wordpress<\/h4>\n<ol>\n<li>\u8fd0\u884cwordpress\u955c\u50cf\uff0c\u5e76\u6301\u4e45\u5316<code>upload<\/code>\u76ee\u5f55<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">docker pull wordpress\ndocker run -d --name=blog \\\n-p 80:80 \\\n-p 443:443 \\\n-e &quot;WORDPRESS_DB_HOST=172.17.0.3&quot; \\\n-e &quot;WORDPRESS_DB_USER=root&quot; \\\n-e &quot;WORDPRESS_DB_PASSWORD=123456&quot; \\\n-e &quot;WORDPRESS_DB_NAME=wordpress&quot; \\\n-v &quot;\/data\/wordpress_uploads\/:\/var\/www\/html\/wp-content\/uploads\/&quot; \\\nwordpress<\/code><\/pre>\n<ol start=\"2\">\n<li>\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\uff0c\u5e76\u9a8c\u8bc1<code>wordpress<\/code>\u7684\u6301\u4e45\u5316<\/li>\n<\/ol>\n<pre><code class=\"language-bash\"># wordpress uploads\u76ee\u5f55\u6743\u9650\u95ee\u9898\ncd \/var\/www\/html\/wp-content\nls -l\ntotal 4\ndrwxrwxrwt. 2 www-data www-data  6 Sep 11 00:01 cache\n-rw-r--r--. 1 www-data www-data 28 Jan  8  2012 index.php\ndrwxr-xr-x. 3 www-data www-data 55 Sep 10 15:23 plugins\ndrwxr-xr-x. 5 www-data www-data 95 Sep 10 15:23 themes\ndrwxr-xr-x. 2 root     root      6 Sep 11 07:45 uploads\n\nchown -R www-data:www-data uploads\/<\/code><\/pre>\n<h3>\u5b89\u88c5linuxcommand\u548cdraw.io<\/h3>\n<p><code>docker run -d --restart=always -p 32768:3000 wcjiang\/linux-command<\/code><br \/>\n<code>docker run -dit --name=drawio -p 9090:8080 -v drawiojs:\/usr\/local\/tomcat\/webapps\/draw\/js\/ --restart=always jgraph\/drawio<\/code><\/p>\n<h3>\u66f4\u65b0\u5bb9\u5668<\/h3>\n<ul>\n<li>\u955c\u50cf\u52a0\u901f\u5730\u5740\uff1a<code>https:\/\/hub.rat.dev<\/code>\u3001<code>https:\/\/docker.1panel.live<\/code><\/li>\n<li>\u62c9\u53d6\u6700\u65b0\u955c\u50cf\uff1a<code>docker pull docker.1panel.live\/wcjiang\/linux-command<\/code><\/li>\n<li>\u505c\u6b62\u5220\u9664\u5bb9\u5668\u540e\u518d\u542f\u52a8\u955c\u50cf\uff1a<code>docker run -d --restart=always -p 32768:3000 docker.1panel.live\/wcjiang\/linux-command<\/code><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6570\u636e\u6301\u4e45\u5316\u4ecb\u7ecd \u4e3a\u4f55\u9700\u8981\u5377 \u5728\u542f\u52a8\u5bb9\u5668\u65f6\uff0cdocker\u4f1a\u52a0\u8f7d\u5bf9\u5e94\u7684\u53ea\u8bfb\u955c\u50cf\u5c42\uff0c\u5e76\u5728\u9876\u90e8\u6dfb\u52a0\u4e00\u4e2a\u8bfb\u5199\u5c42\u3002 \u5728\u5bb9\u5668&#8230; &raquo; <a class=\"read-more-link\" href=\"http:\/\/blue.yn.cn\/?p=1404\">\u9605\u8bfb\u5168\u6587<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-1404","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts\/1404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1404"}],"version-history":[{"count":11,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts\/1404\/revisions"}],"predecessor-version":[{"id":1853,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts\/1404\/revisions\/1853"}],"wp:attachment":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1404"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}