Docker数据存储之tmpfs mounts详解
浏览本文前,但愿你已经对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/
总结
以上就是这篇文章的全部内容了,但愿本文的内容对大家的学习或者工作拥有一定的参考学习价值,感谢大家对脚本之家的支撑。要是你想理解更多相干内容请查看下面相干链接