Docker 17参考手册
引擎: 管理员指南 | Engine: Admin Guide
tmpfs mounts
卷和绑定座默认情况下装入容器的文件系统,它们的内容存储在主机上。
在某些情况下,您可能不希望将容器的数据存储在主机上,但也不希望将数据写入容器的可写层,原因是性能或安全原因,或者数据与非持久性应用程序状态有关。一个例子可能是容器的应用程序创建并根据需要使用的临时一次性密码。
为了让容器访问数据而不需要永久写入数据,可以使用tmpfs
只存储在主机内存中的挂载(如果内存不足,则使用交换)。当容器停止时,tmpfs
安装座被移除。如果容器已提交,tmpfs
则不会保存安装。
选择-tmpfs或-挂载标志。
最初,--tmpfs
标志用于独立容器,--mount
旗号用于群服务。但是,从Docker 17.06开始,您还可以使用--mount
用独立的容器。总的来说,--mount
更明确更详细。最大的区别是--tmpfs
标志不支持任何可配置选项。
针尖新用户应使用
--mount
语法。有经验的用户可能更熟悉--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
标记不能与群集服务一起使用。你必须用--mount
...
tmpfs容器的限制
-
tmpfs
容器之间不能共享挂载。
-
tmpfs
挂载只在Linux容器上工作,而不是在Windows容器上工作。
在容器中使用tmpfs挂载
使用tmpfs
安装在容器中,使用--tmpfs
标志,或使用--mount
旗子type=tmpfs
和destination
选择。没有source
为tmpfs
坐骑。下面的示例创建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选项
tmpfs
挂载允许两个配置选项,这两个选项都不是必需的。如果需要指定这些选项,则必须使用--mount
旗帜,如--tmpfs
旗子不支持他们。
选项 |
描述 |
---|---|
tmpfs的大小 |
tmpfs的大小,以字节为单位。无限制默认。 |
tmpfs的模式 |
tmpfs的八进制文件模式。例如,700或0770.默认为1777或世界可写。 |
下面的示例设置tmpfs-mode
到1770
,因此在容器中它是不可读的。
docker run -d \
-it \
--name tmptest \
--mount type=tmpfs,destination=/app,tmpfs-mode=1770 \
nginx:latest
下一步
- 了解卷
- 了解绑定座
- 了解存储驱动程序
储物,持久力,数据持久性,tmpfs
引擎: 管理员指南 | Engine: Admin Guide相关
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。
主页 | https://docker.com/ |
源码 | https://github.com/docker/docker |
版本 | 17 |
发布版本 | 17.06 |