?
This document uses PHP Chinese website manual Release
創(chuàng)建卷
docker volume create [OPTIONS] [VOLUME]
名字,簡(jiǎn)寫 | 默認(rèn) | 描述 |
---|---|---|
--driver, -d | 本地 | 指定卷驅(qū)動(dòng)程序名稱 |
--label | 設(shè)置卷的元數(shù)據(jù) | |
--name | 指定卷名稱 | |
--opt, -o | map[] | 設(shè)置驅(qū)動(dòng)程序特定選項(xiàng) |
命令 | 描述 |
---|---|
docker volume | 管理卷 |
命令 | 描述 |
---|---|
docker volume create | 創(chuàng)建一個(gè)卷 |
docker volume inspect | 顯示一個(gè)或多個(gè)卷的詳細(xì)信息 |
docker volume ls | 列出卷 |
docker volume prune | 刪除所有未使用的卷 |
docker volume rm | 刪除一個(gè)或多個(gè)卷 |
創(chuàng)建一個(gè)新卷,容器可以在其中使用和存儲(chǔ)數(shù)據(jù)。如果未指定名稱,Docker將生成一個(gè)隨機(jī)名稱。
創(chuàng)建卷,然后配置容器以使用它:
$ docker volume create hello hello $ docker run -d -v hello:/world busybox ls /world
裝入是在容器的內(nèi)部創(chuàng)建的/world
目錄。Docker不支持容器內(nèi)掛載點(diǎn)的相對(duì)路徑。
多個(gè)容器可以在同一時(shí)間段內(nèi)使用相同的卷。如果兩個(gè)容器需要訪問(wèn)共享數(shù)據(jù),這是非常有用的。例如,如果一個(gè)容器寫入而另一個(gè)容器讀取數(shù)據(jù)。
在驅(qū)動(dòng)程序中,卷名必須是唯一的。這意味著您不能對(duì)兩個(gè)不同的驅(qū)動(dòng)程序使用相同的卷名。如果你嘗試docker
返回一個(gè)錯(cuò)誤:
A volume named "hello" already exists with the "some-other" driver. Choose a different volume name.
如果指定當(dāng)前驅(qū)動(dòng)程序上已經(jīng)使用的卷名,Docker假定您希望重用現(xiàn)有卷,并且不返回錯(cuò)誤。
一些卷驅(qū)動(dòng)程序可能會(huì)選擇自定義卷創(chuàng)建。使用-o
或--opt
要傳遞司機(jī)選項(xiàng)的標(biāo)志:
$ docker volume create --driver fake \ --opt tardis=blue \ --opt timey=wimey \ foo
這些選項(xiàng)直接傳遞給卷驅(qū)動(dòng)程序。不同音量驅(qū)動(dòng)程序的選項(xiàng)可能會(huì)執(zhí)行不同的操作(或者根本不執(zhí)行)。
內(nèi)建local
Windows上的驅(qū)動(dòng)程序不支持任何選項(xiàng)。
內(nèi)建local
Linux上的可選接受驅(qū)動(dòng)程序類似于linux的mount
命令。通過(guò)多次傳遞--opt標(biāo)志, 可以提供多個(gè)選項(xiàng)。一些mount
選項(xiàng)(例如o
選項(xiàng))可以采用逗號(hào)分隔的選項(xiàng)列表.??稍诖颂幷业娇捎醚b載選項(xiàng)的完整列表。
例如,下面創(chuàng)建一個(gè)tmpfs
卷叫foo
大小為100兆字節(jié)uid
1000。
$ docker volume create --driver local \ --opt type=tmpfs \ --opt device=tmpfs \ --opt o=size=100m,uid=1000 \ foo
另一個(gè)例子是使用btrfs
*
$ docker volume create --driver local \ --opt type=btrfs \ --opt device=/dev/sda2 \ foo
另一個(gè)使用nfs
安裝/path/to/dir
在rw
模式192.168.1.1
*
$ docker volume create --driver local \ --opt type=nfs \ --opt o=addr=192.168.1.1,rw \ --opt device=:/path/to/dir \ foo