?
This document uses PHP Chinese website manual Release
卷和綁定座默認(rèn)情況下裝入容器的文件系統(tǒng),它們的內(nèi)容存儲(chǔ)在主機(jī)上。
在某些情況下,您可能不希望將容器的數(shù)據(jù)存儲(chǔ)在主機(jī)上,但也不希望將數(shù)據(jù)寫入容器的可寫層,原因是性能或安全原因,或者數(shù)據(jù)與非持久性應(yīng)用程序狀態(tài)有關(guān)。一個(gè)例子可能是容器的應(yīng)用程序創(chuàng)建并根據(jù)需要使用的臨時(shí)一次性密碼。
為了讓容器訪問(wèn)數(shù)據(jù)而不需要永久寫入數(shù)據(jù),可以使用tmpfs
只存儲(chǔ)在主機(jī)內(nèi)存中的掛載(如果內(nèi)存不足,則使用交換)。當(dāng)容器停止時(shí),tmpfs
安裝座被移除。如果容器已提交,tmpfs
則不會(huì)保存安裝。
最初,--tmpfs
標(biāo)志用于獨(dú)立容器,--mount
旗號(hào)用于群服務(wù)。但是,從Docker 17.06開(kāi)始,您還可以使用--mount
用獨(dú)立的容器??偟膩?lái)說(shuō),--mount
更明確更詳細(xì)。最大的區(qū)別是--tmpfs
標(biāo)志不支持任何可配置選項(xiàng)。
針尖新用戶應(yīng)使用
--mount
語(yǔ)法。有經(jīng)驗(yàn)的用戶可能更熟悉--tmpfs
語(yǔ)法,但鼓勵(lì)使用--mount
因?yàn)檠芯勘砻魉菀资褂谩?/p>
--tmpfs
tmpfs
安裝時(shí)不允許您指定任何可配置選項(xiàng),并且只能與獨(dú)立容器一起使用。
--mount
*由多個(gè)鍵值對(duì)組成,以逗號(hào)分隔,每個(gè)鍵值由一個(gè)<key>=<value>
元組。大--mount
語(yǔ)法比-v
或--volume
,但是鍵的順序并不重要,并且標(biāo)志的值更容易理解。
- The `type` of the mount, which can be [`bind`](../bind-mounts-md/index), `volume`, or [`tmpfs`](index). This topic discusses `tmpfs`, so the type will always be `tmpfs`.- The `destination` takes as its value the path where the `tmpfs` mount will be mounted in the container. May be specified as `destination`, `dst`, or `target`.- The `tmpfs-type` and `tmpfs-mode` options. See [tmpfs options](about:blank#tmpfs-options).
下面的示例顯示了--mount
和--tmpfs
在可能的情況下語(yǔ)法,以及--mount
首先介紹。
--tmpfs
和--mount
行為大--tmpfs
標(biāo)志不允許您指定任何可配置選項(xiàng)。
大--tmpfs
標(biāo)記不能與群集服務(wù)一起使用。你必須用--mount
...
tmpfs
容器之間不能共享掛載。
tmpfs
掛載只在Linux容器上工作,而不是在Windows容器上工作。
使用tmpfs
安裝在容器中,使用--tmpfs
標(biāo)志,或使用--mount
旗子type=tmpfs
和destination
選擇。沒(méi)有source
為tmpfs
坐騎。下面的示例創(chuàng)建tmpfs
山/app
在Nginx容器里。第一個(gè)示例使用--mount
標(biāo)志和第二個(gè)使用--tmpfs
旗子。
--mount
--tmpfs
$ docker run -d \ -it \ --name tmptest \ --mount type=tmpfs,destination=/app \ nginx:latest
$ docker run -d \ -it \ --name tmptest \ --tmpfs /app \ nginx:latest
驗(yàn)證掛載是否為tmpfs
跑上山docker container inspect tmptest
尋找Mounts
部分:
"Tmpfs": { "/app": ""},
拆下容器:
$ docker container stop tmptest $ Docker container rm tmptest
tmpfs
掛載允許兩個(gè)配置選項(xiàng),這兩個(gè)選項(xiàng)都不是必需的。如果需要指定這些選項(xiàng),則必須使用--mount
旗幟,如--tmpfs
旗子不支持他們。
選項(xiàng) | 描述 |
---|---|
tmpfs的大小 | tmpfs的大小,以字節(jié)為單位。無(wú)限制默認(rèn)。 |
tmpfs的模式 | tmpfs的八進(jìn)制文件模式。例如,700或0770.默認(rèn)為1777或世界可寫。 |
下面的示例設(shè)置tmpfs-mode
到1770
,因此在容器中它是不可讀的。
docker run -d \ -it \ --name tmptest \ --mount type=tmpfs,destination=/app,tmpfs-mode=1770 \ nginx:latest
了解卷
了解綁定座
了解存儲(chǔ)驅(qū)動(dòng)程序