docker学习——tmpfs mounts

前言

每天一篇博客,高产似那啥,如有错误,欢迎指出

什么是tmpfs mounts

bind mount与volume是持久化数据到磁盘中,在linux上,也可以使用tmpfs mounts,tmpfs mounts是将数据咱存在内存中,当容器停止运行时,对应的tmpfs mounts会消失,存储在内存中的一个好处就是访问速度快,一般情况下,我们不会数据写入到容器的可写层,因为这会增大容器占用的空间,使容器的性能下降

tmpfs mounts的局限

  1. 与volume、bind mount不同,tmpfs mounts不能在容器之间共享,A容器不能访问B容器的tmpfs mounts
  2. tmpfs mounts只在linux上有效

在docker上使用tmpfs mounts

有两种方式,-tmpfs与-mount

  1. -tmpfs:不需要也不能指定任何参数,可以将容器挂载到一个tmpfs mounts上
  2. -mount:包含多个键值对,用逗号分割,具有如下含义
    type:挂载点的类型,在本节中应该使用tmpfs
    destination:需要挂载到tmpfs的容器文件/目录的路径
    tmpfs-size:tmpfs的容量,以字节为单位,默认情况下没有限制
    tmpfs-mode:tmpfs的文件权限(请查看linux中的相应内容),默认是1777

关于两者的使用例子,请查看:https://docs.docker.com/storage/tmpfs/#use-a-tmpfs-mount-in-a-container

两者的不同:-tmpfs只能用于单个容器,-mount可用于swarm service,如果docker版本大于17.06,则-mount也可用于单个容器,tmpfs不可以指定参数,而-mount可以

接下来就该解析存储驱动了,操作系统不同,推荐使用的存储驱动也不同

猜你喜欢

转载自blog.csdn.net/dhaiuda/article/details/83149190