您好,登錄后才能下訂單哦!
1.將數(shù)據(jù)從宿主機(jī)掛載到容器中的三種方式
Docker提供三種方式將數(shù)據(jù)從宿主機(jī)掛載到容器中:? ??volumes:Docker管理宿主機(jī)文件系統(tǒng)的一部分(/var/lib/docker/volumes)。保存數(shù)據(jù)的最佳方式。? ??bind?mounts:將宿主機(jī)上的任意位置的文件或者目錄掛載到容器中。? ??tmpfs:掛載存儲在主機(jī)系統(tǒng)的內(nèi)存中,而不會寫入主機(jī)的文件系統(tǒng)。如果不希望將數(shù)據(jù)持久存儲在任何位置,可以使用?tmpfs,同時避免寫入容器可寫層提高性能。
2.Volume
創(chuàng)建卷: docker?volume?create?nginx-vol 查看卷: docker?volume?ls docker?volume?inspect?nginx-vol 掛載卷: docker?run?-d?-p?89:80?--name=nginx-test?--mount?src=nginx-vol,dst=/usr/share/nginx/html?nginx? docker?run?-d?-p?89:80?--name=nginx-test?-v?nginx-vol:/usr/share/nginx/html?nginx? 刪除卷: docker?rm?-f?$(docker?ps?-a?|awk?'{print?$1}') docker?rm?-f?$(docker?ps?-qa) docker?volume?rm?nginx-vol 注意:? 1.?如果沒有指定卷,自動創(chuàng)建。? 2.?建議使用--mount,更通用
3.Bind Mounts
用卷創(chuàng)建一個容器: docker?run?-d?-it?--name=nginx-test?--mount?type=bind,src=/app/wwwroot,dst=/usr/share/nginx/html?nginx docker?run?-d?-it?--name=nginx-test?-v?/app/wwwroot:/usr/share/nginx/html?nginx? 驗(yàn)證綁定: docker?inspect?nginx-test? 清理: docker?stop?nginx-test docker?rm?nginx-test? 注意:?1.?如果源文件/目錄沒有存在,不會自動創(chuàng)建,會拋出一個錯誤。?2.?如果掛載目標(biāo)在容器中非空目錄,則該目錄現(xiàn)有內(nèi)容將被隱藏 [root@localhost?~]#?mkdir?wwwroot;touch?wwwroot/index.html [root@localhost?~]#?docker?run?-d?-p?89:80?--mount?type=bind,src=$PWD/wwwroot,dst=/usr/share/nginx/html?nginx 9c675487b319d6a723f2de35abd09c465aca6472b91e7232a9de6893012f3f63 [root@localhost?~]#?docker?ps CONTAINER?ID????????IMAGE???????????????COMMAND??????????????????CREATED?????????????STATUS??????????????PORTS????????????????NAMES 9c675487b319????????nginx???????????????"nginx?-g?'daemon?of…"???9?seconds?ago???????Up?8?seconds????????0.0.0.0:89->80/tcp???sad_robinson [root@localhost?~]#?docker?exec?-it?9c675487b319?bash root@9c675487b319:/#?ls?/usr/share/nginx/html index.html root@9c675487b319:/#?cat?/usr/share/nginx/html/index.html? root@9c675487b319:/#?exit exit [root@localhost?~]#?cat?wwwroot/index.html? [root@localhost?~]#?echo?"hello"?>wwwroot/index.html? [root@localhost?~]#?docker?exec?-it?9c675487b319?cat?/usr/share/nginx/html/index.html hello [root@localhost?~]#?docker?rm?-f?9c675487b 9c675487b [root@localhost?~]#?cat?wwwroot/index.html? hello [root@localhost?~]#
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。