欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

          詳細(xì)介紹docker數(shù)據(jù)卷管理&convoy卷插件(實(shí)例詳解)

          本篇文章給大家?guī)砹岁P(guān)于docker中數(shù)據(jù)卷管理和convoy卷插件的相關(guān)知識,希望對大家有幫助。

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)

          1.什么是Docker數(shù)據(jù)卷

          • 數(shù)據(jù)卷是一個(gè)或多個(gè)容器中專門指定的目錄,它能夠繞過聯(lián)合文件系統(tǒng)。
            卷被設(shè)計(jì)用作數(shù)據(jù)持久化、并且是獨(dú)立于容器的生命周期的。

          • 因此,Docker不會(huì)在刪除容器時(shí)自動(dòng)刪除數(shù)據(jù)卷卷,也不會(huì)主動(dòng)“垃圾回收”掉容器不再使用的卷。

          • 數(shù)據(jù)卷的存在就是想讓的容器的數(shù)據(jù)持久化存在,而且可以實(shí)現(xiàn)容器之間的數(shù)據(jù)共享。

          • 通俗地來說,docker容器數(shù)據(jù)卷可以看成使我們生活中常用的u盤,它存在于一個(gè)或多個(gè)的容器中,由docker掛載到容器,但不屬于聯(lián)合文件系統(tǒng),Docker不會(huì)在容器刪除時(shí)刪除其掛載的數(shù)據(jù)卷。

          2.為什么要用數(shù)據(jù)卷

          docker分層文件系統(tǒng):

          • 性能差
          • 生命周期與容器相同

          docker數(shù)據(jù)卷:

          • mount到主機(jī)中,繞開分層文件系統(tǒng)
          • 和主機(jī)磁盤性能相同,容器刪除后依然保留
          • 僅限本地磁盤,不能隨容器遷移

          3.docker數(shù)據(jù)卷提供兩種卷

          bind mount

          是將主機(jī)上的目錄或文件mount到容器里

          • 使用直觀高效,易于理解。
          • 使用 -v 選項(xiàng)指定路徑,格式 :
          • bind mount 默認(rèn)權(quán)限是讀寫rw,可以在掛載時(shí)指定只讀ro。
          • -v選項(xiàng)指定的路徑,如果不存在,掛載時(shí)會(huì)自動(dòng)創(chuàng)建。

          docker managed volume

          bind mount必須指定host文件系統(tǒng)路徑,限制了移植性。
          docker managed volume 不需要指定mount源

          bind mount 和docker managed volume對比

          相同點(diǎn):兩者都是host文件系統(tǒng)中的某個(gè)路徑

          不同點(diǎn):
          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)

          4.bind mount應(yīng)用

          docker network prune  docker network ls docker run -d --name vm1 -v /opt/website:/usr/share/nginx/html nginx docker ps

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)

          docker inspect vm1	#查看到ip為172.17.0.2 curl 172.17.0.2

          發(fā)現(xiàn)是403頁面:
          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)

          cd /opt/website/ ls	#發(fā)現(xiàn)沒有默認(rèn)發(fā)布頁面 echo www.westos.org > index.html curl 172.17.0.2

          此時(shí)訪問nginx,就有www.westos.org內(nèi)容了:
          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)
          掛載時(shí)還可以指定權(quán)限:

          docker run -it --rm -v /opt/website:/data1 -v /etc/passwd:/data2/passwd:ro busybox

          可以看到默認(rèn)權(quán)限為rw讀寫,所以我們可以更改index.html的內(nèi)容;而指定passwd為只讀后,我們就無法修改其內(nèi)容,只能讀
          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)

          5.docker managed volume

          查看現(xiàn)有的管理卷:

          docker volume ls

          我們有些是時(shí)候在刪除了容器后會(huì)有殘存的管理卷存在,這是我們就需要去清理它,不然會(huì)占用我們的資源:

          docker volume prune  docker volume ls

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)

          docker run -d --name registry registry cd /var/lib/docker/volumes/ ls docker history registry:latest

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)
          通過docker volume可以將容器內(nèi)的內(nèi)容復(fù)制到掛載點(diǎn):

          docker run -d --name vm2 -v /usr/share/nginx/html nginx cd /var/lib/docker/volumes/ ls cd 674c999f99b7b524d8f5769b65cb5411d11e3fa855da695a5fdd3494e4342d89/ cd _data/ ls	#查看到默認(rèn)發(fā)布目錄被復(fù)制到了這里

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)

          docker inspect vm2 curl 172.17.0.3	#nginx默認(rèn)發(fā)布頁

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)

          echo hello docker! > index.html curl 172.17.0.3	#可以直接在掛載的目錄修改默認(rèn)發(fā)布頁

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)

          6.docker卷插件簡介

          docker卷默認(rèn)使用的是local類型的驅(qū)動(dòng),只能存在宿主機(jī),
          跨主機(jī)的volume就需要使用第三方的驅(qū)動(dòng)
          ,可以查看鏈接:
          https://docs.docker.com/engine/extend/legacy_plugins/#volume-plugins
          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)

          Docker Plugin 是以Web Service的服務(wù)運(yùn)行在每一臺(tái)Docker Host上的,通過HTTP協(xié)議傳輸RPC風(fēng)格的JSON數(shù)據(jù)完成通信。Plugin的啟動(dòng)和停止,并不歸Docker管理,Docker Daemon依靠在缺省路徑下查找Unix Socket文件,自動(dòng)發(fā)現(xiàn)可用的插件。
          當(dāng)客戶端與Daemon交互,使用插件創(chuàng)建數(shù)據(jù)卷時(shí),Daemon會(huì)在后端找到插件對應(yīng)的 socket 文件,建立連接并發(fā)起相應(yīng)的API請求,最終結(jié)合Daemon自身的處理完成客戶端的請求。

          7.convoy卷插件

          convoy卷插件支持三種運(yùn)行方式:devicemapper、NFS、EBS。下面的實(shí)驗(yàn)以nfs的運(yùn)行方式來演示

          實(shí)驗(yàn)?zāi)康模涸趕erver1和2底層用nfs來實(shí)現(xiàn)數(shù)據(jù)共享

          step1 首先在server1和server2上搭建nfs文件系統(tǒng):

          server1:

          yum install -y nfs-utils systemctl start rpcbind	 mkdir /nfs	#創(chuàng)建共享目錄 chmod 777 /nfs	#修改共享目錄權(quán)限 vim /etc/exports	#編輯共享目錄文件,否則將不會(huì)被共享出去 /nfs	*(rw,no_root_squash) systemctl start nfs

          注意:rpcbind服務(wù)必須是開啟的。這是因?yàn)椋核且粋€(gè)RPC服務(wù),主要是在nfs共享時(shí)候負(fù)責(zé)通知客戶端,服務(wù)器的nfs端口號的。簡單理解rpc就是一個(gè)中介服務(wù)。
          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)
          server2:

          yum install -y nfs-utils systemctl start nfs-server.service showmount -e server1	#尋找server1的掛載目錄 mkdir /nfs mount server1:/nfs /nfs df

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)
          測試:
          在server2中:

          cd /nfs/ touch file

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)
          在server1中:

          cd /nfs/ ls	#查看到file

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)
          說明兩個(gè)節(jié)點(diǎn)的/nfs實(shí)現(xiàn)同步了

          step2 配置convoy環(huán)境:
          docker官方只提供了卷插件的api,開發(fā)者可以根據(jù)實(shí)際需求定制卷插件驅(qū)動(dòng)。

          在server1中:

          tar zxf convoy.tar.gz  cd convoy/ cp convoy* /usr/local/bin/  #將二進(jìn)制文件加入到PATH路徑 mkdir /etc/docker/plugins	#創(chuàng)建docker的插件目錄 convoy daemon --drivers vfs --driver-opts vfs.path=/nfs &> /dev/null & cd /nfs ls

          注意:第一次運(yùn)行上面的convoy daemon命令的時(shí)候,會(huì)在/nfs目錄下生成一個(gè)config文件夾,這個(gè)文件夾不要?jiǎng)h除,不然客戶端的convoy命令就會(huì)用不了

          echo "unix:///var/run/convoy/convoy.sock" > /etc/docker/plugins/convoy.spec #將convoy守護(hù)進(jìn)程開啟生成的.sock文件放入/etc/docker/plugins目錄下的convoy.spec文件中,docker就可以識別。(其中convoy.spec文件之前是不存在的) cat /etc/docker/plugins/convoy.spec

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)
          在server2中同樣配置convoy環(huán)境:

          scp -r server1:convoy . cd convoy/ cp convoy* /usr/local/bin/  #將二進(jìn)制文件加入到PATH路徑 mkdir /etc/docker/plugins	#創(chuàng)建docker的插件目錄 echo "unix:///var/run/convoy/convoy.sock" > /etc/docker/plugins/convoy.spec convoy daemon --drivers vfs --driver-opts vfs.path=/nfs &> /dev/null & cd /nfs ls

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)
          step3 創(chuàng)建卷:

          docker volume ls convoy create vol1

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)
          step4 操作卷:

          在server2中運(yùn)行容器,指定卷為剛才新創(chuàng)建的vol1:

          docker run -it --name vm1 -v vol1:/usr/share/nginx/html nginx docker ps docker inspect vm1 curl 172.17.0.2	#nginx默認(rèn)發(fā)布頁

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)
          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)

          cd /nfs/ cd vol1/ echo hello convoy > index.html curl 172.17.0.2

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)
          在server1中數(shù)據(jù)也同步了:

          cd /nfs/ cd vol1/ cat index.html

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)
          在ser1中也可以運(yùn)行容器,也可以用到共享的數(shù)據(jù)卷

          說明:docker引擎默認(rèn)掃描 /etc/docker/plugins目錄中的convoy.spec—>訪問/run/convoy/convoy.sock文件—>發(fā)起響應(yīng)的api請求—>把數(shù)據(jù)寫入vol1中—>底層通過nfs進(jìn)行主機(jī)間的數(shù)據(jù)同步

          如何刪除通過nfs創(chuàng)建的數(shù)據(jù)卷,讓之后創(chuàng)建的數(shù)據(jù)卷都是本地的呢?

          刪除卷:

          convoy delete vol1

          實(shí)現(xiàn)本地驅(qū)動(dòng):

          cd /etc/docker/plugins/ mv convoy.spec /mnt systemctl restart docker

          創(chuàng)建卷:

          docker volume create vol1 ls cd volumes/ ls	#可以看到vol1,默認(rèn)創(chuàng)建在這個(gè)目錄下 cd vol1/ ls cd _data/ ls	#進(jìn)入該目錄,是空的

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)
          使用卷:

          docker run -d --name vm1 -v vol1:/usr/share/nginx/html nginx docker ps ls	#看到nginx默認(rèn)發(fā)布目錄被掛到這里了

          詳細(xì)介紹docker數(shù)據(jù)卷管理&amp;convoy卷插件(實(shí)例詳解)
          補(bǔ)充幾條命令:

          docker container prune	#刪除停止的容器 docker volume prune	#刪除沒有被使用的卷

          推薦學(xué)習(xí):《docker視頻教程》

          贊(0)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號