{"id":160850,"date":"2019-10-30T09:00:43","date_gmt":"2019-10-30T01:00:43","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=160850"},"modified":"2019-10-17T10:55:18","modified_gmt":"2019-10-17T02:55:18","slug":"docker-data-volumes","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/docker-data-volumes.html","title":{"rendered":"Docker\u6570\u636e\u7ba1\u7406\u65b9\u5f0f"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u4f7f\u7528docker\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u67e5\u770b\u5bb9\u5668\u4e2d\u4ea7\u751f\u7684\u6570\u636e\uff0c\u4ee5\u53ca\u5bb9\u5668\u4e0e\u5bb9\u5668\u4e4b\u95f4\u3001\u5bb9\u5668\u4e0e\u4e3b\u673a\u4e4b\u524d\u8fdb\u884c\u6570\u636e\u5171\u4eab\u3001\u5907\u4efd\u7b49\u64cd\u4f5c\uff0c\u8fd9\u91cc\u5c31\u9700\u8981\u5230\u5bb9\u5668\u7684\u6570\u636e\u7ba1\u7406\u3002 <\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u6570\u636e\u7684\u7ba1\u7406\u76ee\u524d\u63d0\u4f9b\u5982\u4e0b\u4e24\u79cd\u65b9\u5f0f\uff1a<\/p>\n

\uff081\uff09\u6570\u636e\u5377 data volumes<\/p>\n

\uff082\uff09\u6570\u636e\u5377\u5bb9\u5668 data volumes containers<\/p>\n

\u6570\u636e\u5377<\/strong><\/div>\n

\u6570\u636e\u5377\uff0c\u8bf4\u767d\u4e86\u5c31\u662f\u4e00\u4e2a\u7279\u6b8a\u76ee\u5f55\uff0c\u7c7b\u4f3clinux\u4e0b\u5bf9\u76ee\u5f55\u6216\u6587\u4ef6\u8fdb\u884cmount\u6302\u8f7d\u64cd\u4f5c\uff0c\u53ea\u4e0d\u8fc7\u4ed6\u7ed5\u8fc7\u4e86\u6587\u4ef6\u7cfb\u7edf\u3002\u5177\u6709\u5982\u4e0b\u7279\u70b9\uff1a<\/p>\n

\uff081\uff09\u6570\u636e\u5377\u53ef\u4ee5\u5728\u5bb9\u5668\u4e4b\u95f4\u8fdb\u884c\u5171\u4eab\u548c\u91cd\u7528<\/p>\n

\uff082\uff09\u5bf9\u6570\u636e\u5377\u7684\u66f4\u6539\u4f1a\u7acb\u5373\u751f\u6548<\/p>\n

\uff083\uff09\u5bf9\u6570\u636e\u5377\u7684\u66f4\u65b0\u4e0d\u4f1a\u5f71\u54cd\u5230\u955c\u50cf \uff08\u955c\u50cf\u53ea\u8bfb\uff09<\/p>\n

\uff084\uff09\u5377\u4f1a\u4e00\u76f4\u5b58\u5728\uff0c\u76f4\u5230\u6ca1\u6709\u5bb9\u5668\u4f7f\u7528<\/p>\n

\u6570\u636e\u5377\u7684\u6dfb\u52a0\u53ef\u4ee5\u901a\u8fc7-v \u53c2\u6570\u6765\u8bbe\u5b9a\uff0c\u540e\u8fb9\u8ddf\u4e0a\u76ee\u5f55\u3002\u4e00\u4e0b\u4e3e\u4f8b\u8bf4\u660e\uff1a<\/p>\n

\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5377\/homedata\u5230\u5bb9\u5668os123\u4e2d<\/strong><\/span><\/div>\n
\r\n[root@docker5 home]# docker  run  -d -ti --name os123   -v  \/homedata  centos\r\n[root@docker5 home]# docker  exex  -ti os123 \/bin\/bash\r\n[root@d1a05a7d5efe \/]# ll\r\ntotal 40\r\n-rw-r--r--. 1 root root 18301 Jun 2 13:27 anaconda-post.log\r\nlrwxrwxrwx. 1 root root 7 Jun 2 13:25 bin > usr\/bin\r\ndrwxr-xr-x. 5 root root 380 Jun 23 02:42 dev\r\ndrwxr-xr-x. 48 root root 4096 Jun 23 02:42 etc\r\ndrwxr-xr-x. 2 root root 6 Aug 12 2015 home\r\ndrwxr-xr-x. 2 root root 6 Jun 23 02:42 homedata\r\n..\r\n[root@d1a05a7d5efe \/]# cd homedata\/\r\n[root@d1a05a7d5efe homedata]# ll\r\ntotal 0\r\n[root@d1a05a7d5efe homedata]# touch  21yunwei.txt ;echo 123>> 21yunwei.txt\r\n[root@d1a05a7d5efe homedata]# cat  21yunwei.txt \r\n123\r\n<\/pre>\n
\u6302\u8f7d\u672c\u5730\u670d\u52a1\u5668\u4e0a\u7684\u4e00\u4e2a\u76ee\u5f55\/home\/data\u5230\u5bb9\u5668os456 \u76ee\u5f55\/homedata\u4e2d<\/strong><\/span><\/div>\n

home\/data\u4e8b\u5148\u91cc\u8fb9\u5efa\u7acb\u4e00\u4e2a\u6587\u4ef61.txt\u5e76\u5185\u5bb9hello world<\/p>\n

\r\n[root@docker5 home]# docker run  -d -ti --name os456 -v \/home\/data:\/homedata centos\r\n[root@docker5 home]# docker exec  -ti os456  \/bin\/bash\r\n[root@9347d5ef84ff homedata]# cd \/homedata;cat  1.txt \r\nhello world\r\n<\/pre>\n

\u901a\u8fc7\u4e0a\u8fb9\u4e24\u4e2a\u5bb9\u5668os123 \u548cos456\uff0c\u57fa\u672c\u4e86\u89e3\u4e86\u5982\u4f55\u521b\u5efa\u6570\u636e\u5377\u4ee5\u53ca\u5982\u4f55\u6302\u8f7d\u672c\u5730\u76ee\u5f55\u5230\u6570\u636e\u5377\u4e2d\u3002\u6ce8\u610f\uff0c\u4e24\u4e2a\u5bb9\u5668\u4e2d\u7684\u5982\u679c\u662f\u5355\u72ec\u6302\u8f7d\u7684\u6570\u636e\u5377\uff08\u5373\u6ca1\u6709\u6302\u8f7d\u540c\u4e00\u4e2a\u6570\u636e\u5377\u5bb9\u5668\uff09\uff0c\u90a3\u4e48\u6570\u636e\u662f\u4e92\u4e0d\u5f71\u54cd\u7684\uff0c\u8fdb\u5165\u4e0d\u540c\u7684\u6570\u636e\u5377\u76f8\u540c\u76ee\u5f55\u4e0b\u6bd4\u5982\/homedata\uff0c\u5185\u5bb9\u53ef\u4ee5\u4e0d\u4e00\u6837\u3002<\/p>\n

\u6ce8\u610f\uff1a\u5220\u9664\u5bb9\u5668\u7684\u65f6\u5019\uff0c\u6570\u636e\u5377\u4e0d\u4f1a\u5220\u9664\u3002\u5982\u679c\u8981\u5220\u9664\u5bb9\u5668\u7684\u65f6\u5019\u540c\u65f6\u5220\u9664\u6570\u636e\u5377\uff0c\u9700\u52a0\u4e0a-v\u53c2\u6570\u3002\u6bd4\u5982: docker rm os456 -v \/homedata<\/p>\n

\u6570\u636e\u5377\u5bb9\u5668<\/strong><\/div>\n

\u5efa\u7acb\u7684\u5bb9\u5668\u5f88\u591a\u65f6\u5019\u4e0d\u662f\u5355\u4e00\u7684\uff0c\u9700\u8981\u5bb9\u5668\u4e4b\u95f4\u8fdb\u884c\u6570\u636e\u5171\u4eab\uff0c\u8fdb\u884c\u6570\u636e\u540c\u6b65\u548c\u66f4\u65b0\u64cd\u4f5c\u3002\u8fd9\u6837\u5c31\u9700\u8981\u5efa\u7acb\u4e00\u4e2a\u6570\u636e\u5377\u5bb9\u5668\u3002<\/p>\n

\u6570\u636e\u5377\u5bb9\u5668\u5c31\u662f\u4e00\u4e2a\u666e\u901a\u7684\u5bb9\u5668\uff0c\u91cc\u8fb9\u5e26\u6709\u8bbe\u7f6e\u597d\u7684\u6570\u636e\u5377\uff0c\u4e13\u95e8\u63d0\u4f9b\u7ed9\u5176\u4ed6\u5bb9\u5668\u6302\u8f7d\u4f7f\u7528\u3002 \u901a\u8fc7\u2013volumes-from \u6570\u636e\u5377\u5bb9\u5668\u540d \u6765\u5b9e\u73b0\u3002<\/p>\n

\u6211\u6709\u4e00\u4e2a\u7f51\u7ad9\u7a0b\u5e8f\u653e\u5230\u4e86\u670d\u52a1\u5668\u672c\u673a\u7684\/home\/webdata\u76ee\u5f55 \uff0c\u4e0b\u8fb9\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5377\u5bb9\u5668webdata\uff0c\u540c\u65f6\u5c06\u6211\u670d\u52a1\u5668\u4e0a\u7684\/home\/webdata\u6302\u8f7d\u5230\u6570\u636e\u5377\u5bb9\u5668\u7684\/web\u76ee\u5f55\uff1a<\/p>\n

\r\n[root@docker5 home]# docker  run  -d  -ti  --name webdata   -v  \/home\/webdata:\/home\/web  centos\r\n<\/pre>\n

\u8fdb\u5165\u5bb9\u5668\u5e76\u67e5\u770b\u6570\u636e<\/p>\n

\r\n[root@docker5 home]# docker exec  -ti  webdata  \/bin\/bash\r\n[root@289598d6e24d \/]# cd  \/home\/web\/\r\n[root@289598d6e24d web]# ll\r\ntotal 7872\r\ndrwxr-xr-x. 3 root root      54 Mar 27  2013 META-INF\r\ndrwxr-xr-x. 6 root root    4096 Dec 25  2014 WEB-INF\r\ndrwxr-xr-x. 3 root root      63 Mar 27  2013 css\r\ndrwxr-xr-x. 2 root root    8192 Mar 27  2013 flags\r\n-rw-r--r--. 1 root root      97 Mar 27  2013 index.jsp\r\ndrwxr-xr-x. 2 root root    4096 Mar 27  2013 js\r\ndrwxr-xr-x. 2 root root       6 Jun 23 03:43 probe\r\n<\/pre>\n

\u901a\u8fc7\u8fd9\u91cc\u5efa\u7acb1.txt \u5e76\u63d2\u5165\u5185\u5bb9\uff0c\u53ef\u4ee5\u770b\u5230\u670d\u52a1\u5668\u4e0a\u7684\/home\/webdata\u6570\u636e\u662f\u540c\u6b65\u7684\u3002\u53ef\u89c1\u5bb9\u5668\u4ee5\u53ca\u76ee\u5f55\u6302\u8f7d\u90fd\u6ca1\u95ee\u9898\u3002<\/p>\n

\r\n[root@docker5 home]# docker  run  -dti --volumes-from webdata --name os147 centos\r\n[root@docker5 home]# docker  run  -dti --volumes-from webdata --name os258 centos\r\n<\/pre>\n

\u5206\u522b\u521b\u5efa\u4e86\u4e24\u4e2a\u5bb9\u5668\uff0c\u90fd\u901a\u8fc7\u2013volumes-from webdata \u6302\u8f7d\u4e86\u540c\u4e00\u4e2a\u6570\u636e\u5377\u5bb9\u5668\uff0c\u8fdb\u5165os147 \u548cos258 \u5206\u522b\u67e5\u770b\/home\/web\u53ef\u89c1\u6570\u636e\u90fd\u662f\u5b58\u5728\u7684\uff0c\u4e8e\u662f\u8fd9\u91cc\u5c31\u5b9e\u73b0\u4e86\u6570\u636e\u7684\u5171\u4eab\u540c\u6b65\u3002<\/p>\n

\r\n[root@docker5 home]# docker exec  -ti  os147  \/bin\/bash\r\n[root@b4cfa4c4e11c \/]# cd  \/home\/web\/\r\n[root@b4cfa4c4e11c web]# ll\r\ntotal 7876\r\n-rw-r--r--. 1 root root      11 Jun 23 03:46 1.txt\r\ndrwxr-xr-x. 3 root root      54 Mar 27  2013 META-INF\r\ndrwxr-xr-x. 6 root root    4096 Dec 25  2014 WEB-INF\r\ndrwxr-xr-x. 3 root root      63 Mar 27  2013 css\r\ndrwxr-xr-x. 2 root root    8192 Mar 27  2013 flags\r\n-rw-r--r--. 1 root root      97 Mar 27  2013 index.jsp\r\ndrwxr-xr-x. 2 root root    4096 Mar 27  2013 js\r\ndrwxr-xr-x. 2 root root       6 Jun 23 03:43 probe\r\n<\/pre>\n

\u8bf4\u660e\uff1a<\/p>\n

1\uff0c\u53ef\u4ee5\u591a\u6b21\u4f7f\u7528\u2013volume-from\u53c2\u6570\u4ece\u591a\u4e2a\u5bb9\u5668\u6302\u8f7d\u591a\u4e2a\u76ee\u5f55\u3002 \u4e5f\u53ef\u4ee5\u4ece\u5176\u4ed6\u5df2\u7ecf\u6302\u8f7d\u4e86\u6570\u636e\u5377\u7684\u5bb9\u5668\u6765\u6302\u8f7d\u6570\u636e\u5377\uff08\u7c7b\u4f3c\u4f20\u9012\uff09\u3002<\/p>\n

2\uff0c\u518d\u6b21\u5f3a\u8c03\uff1a\u5982\u679c\u5220\u9664\u4e86\u6302\u8f7d\u7684\u5bb9\u5668\uff0c\u6570\u636e\u5377\u4e0d\u4f1a\u88ab\u81ea\u52a8\u5220\u9664\u3002\u5982\u679c\u8981\u5220\u9664\u5bb9\u5668\u7684\u65f6\u5019\u540c\u65f6\u5220\u9664\u6570\u636e\u5377\uff0c\u9700\u52a0\u4e0a-v\u53c2\u6570\u3002<\/p>\n

\u901a\u8fc7\u6570\u636e\u5377\u5bb9\u5668\u8fdb\u884c\u6570\u636e\u5907\u4efd\u3001\u6570\u636e\u6062\u590d\u548c\u6570\u636e\u8fc1\u79fb<\/strong><\/div>\n
\u5907\u4efd<\/strong><\/span><\/div>\n

\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u4e13\u95e8\u7528\u6765\u5907\u4efdprobe\u7684\u5bb9\u5668\uff1aprobebak\u8fdb\u884c\u5907\u4efd\u6570\u636e\u5377\u5bb9\u5668\u4e2d\u7684\u6570\u636e\uff0c\u547d\u4ee4\u5982\u4e0b<\/p>\n

\r\n docker run  -dti --volumes-from webdata  --name probebak -v \/home\/web_probebak:\/backup   centos tar zcvf \/backup\/web_probe.tar.gz  \/home\/web\r\n<\/pre>\n

\u547d\u4ee4\u4e3a\u521b\u5efa\u4e00\u4e2a\u4e13\u7528\u5907\u4efd\u7684\u5bb9\u5668probebak\uff0c\u6302\u8f7d\u4e86\u6570\u636e\u5377\u5bb9\u5668webdata\uff0c\u540c\u65f6\u5c06\u670d\u52a1\u5668\u672c\u5730\u76ee\u5f55 \/home\/web_probebak\u6302\u8f7d\u5230\u4e86\u5907\u4efd\u5bb9\u5668\u4e0a\u7684\/backup\u76ee\u5f55\u5bb9\u5668\u542f\u52a8\u4ee5\u540e\uff0c\u4f1a\u6267\u884ctar zcvf \/backup\/web_proce.tar.gz \/home\/web\u64cd\u4f5c\uff0c\u5b8c\u6210\u670d\u52a1\u5668\u4e0a\/home\/web\u5907\u4efd\uff0c\u6253\u5305\u5230\/backup\/web_proce.tar.gz\uff0c\u4e5f\u5c31\u662f\u6253\u5305\u5230\u4e86\/home\/web_probebak\/web_probe.tar.gz \u5b9e\u73b0\u4e86\u6570\u636e\u5907\u4efd\u3002<\/p>\n

\u6062\u590d<\/strong><\/span><\/div>\n

\u521b\u5efa\u4e00\u4e2a\u5bb9\u5668os999 \uff0c\u6302\u8f7d\u6709\u6570\u636e\u5377 \/testdata<\/p>\n

\r\n[root@docker5 home]# docker run  -v  \/testdata --name os999  centos  \/bin\/bash\r\n<\/pre>\n

\u518d\u5efa\u4e00\u4e2a\u5bb9\u5668\uff0c\u901a\u8fc7\u2013volumes-from os999\u6302\u8f7d\u521a\u624d\u8bbe\u7f6e\u597d\u7684\u6570\u636e\u5377\uff0c\u89e3\u538b\u6570\u636e\uff1a<\/p>\n

\r\n[root@docker5 home]# docker run --volumes-from os999 -v \/home\/web_probebak:\/backup busybox tar zxvf \/backup\/web_probe.tar.gz\r\nUsage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.\r\nhome\/web\/\r\nhome\/web\/probe.zip\r\nhome\/web\/probe\/\r\nhome\/web\/css\/\r\nhome\/web\/css\/classic\/\r\nhome\/web\/css\/classic\/datasourcetest.css\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u6570\u636e\u7684\u7ba1\u7406\u76ee\u524d\u63d0\u4f9b\u5982\u4e0b\u4e24\u79cd\u65b9\u5f0f\uff1a \uff081\uff09\u6570\u636e\u5377 data volumes \uff082\uff09\u6570\u636e\u5377\u5bb9\u5668 data volu […]<\/p>\n","protected":false},"author":668,"featured_media":38342,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-160850","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/160850","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=160850"}],"version-history":[{"count":9,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/160850\/revisions"}],"predecessor-version":[{"id":161593,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/160850\/revisions\/161593"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/38342"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=160850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=160850"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=160850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}