閱讀本文前,希望你已經對Volumes和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
參考文章
https://docs.docker.com/storage/tmpfs/
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對VEVB武林網的支持。
新聞熱點
疑難解答
圖片精選