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