Docker数据存储之tmpfs mounts详解
author:一佰互联 2019-04-22   click:168

阅读本文前,希望你已经对Volumes和Bind mounts有了初步的了解,具体可以参考以下文章:

  • Docker数据持久化之Volumes
  • Docker数据持久化之Bind mounts

tmpfs mounts

Volumes和Bind mounts模式使我们能够在宿主机和容器间共享文件从而我们能够将数据持久化到宿主机上,以避免写入容器存储层带来的容器停止后数据的丢失的问题。

如果你使用linux运行Docker,那么避免写入数据到容器存储层还有一个方案:tmpfs mounts。

tmpfs mounts,顾名思义,是一种非持久化的数据存储。它仅仅将数据保存在宿主机的内存中,一旦容器停止运行,tmpfs mounts会被移除,从而造成数据丢失。

tmpfs mounts的使用

我们可以在运行容器时通过指定--tmpfs参数或--mount参数来使用tmpfs mounts:

$ docker run -d  -it  --name tmptest  --mount type=tmpfs,destination=/app  nginx:latest
$ docker run -d  -it  --name tmptest  --tmpfs /app  nginx:latest

使用--tmpfs参数无法指定任何其他的可选项,并且不能用于Swarm Service。

使用docker container inspect tmptest命令,然后查看Mounts部分可以看到:

"Tmpfs": { "/app": ""},

tmpfs mounts 可选选项

一个例子:

docker run -d  -it  --name tmptest  --mount type=tmpfs,destination=/app,tmpfs-mode=1770  nginx:latest

tmpfs mounts使用场景

请参考这篇文章:Docker数据存储总结

参考文章

https://docs.docker.com/storage/tmpfs/

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对网页设计的支持。如果你想了解更多相关内容请查看下面相关链接