Docker數(shù)據(jù)存儲(chǔ)之tmpfs mounts詳解
閱讀本文前,希望你已經(jīng)對(duì)Volumes和Bind mounts有了初步的了解,具體可以參考以下文章:
- Docker數(shù)據(jù)持久化之Volumes
- Docker數(shù)據(jù)持久化之Bind mounts
tmpfs mounts
Volumes和Bind mounts模式使我們能夠在宿主機(jī)和容器間共享文件從而我們能夠?qū)?shù)據(jù)持久化到宿主機(jī)上,以避免寫入容器存儲(chǔ)層帶來的容器停止后數(shù)據(jù)的丟失的問題。
如果你使用linux運(yùn)行Docker,那么避免寫入數(shù)據(jù)到容器存儲(chǔ)層還有一個(gè)方案:tmpfs mounts。
tmpfs mounts,顧名思義,是一種非持久化的數(shù)據(jù)存儲(chǔ)。它僅僅將數(shù)據(jù)保存在宿主機(jī)的內(nèi)存中,一旦容器停止運(yùn)行,tmpfs mounts會(huì)被移除,從而造成數(shù)據(jù)丟失。
tmpfs mounts的使用
我們可以在運(yùn)行容器時(shí)通過指定--tmpfs參數(shù)或--mount參數(shù)來使用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參數(shù)無法指定任何其他的可選項(xiàng),并且不能用于Swarm Service。
使用docker container inspect tmptest命令,然后查看Mounts部分可以看到:
"Tmpfs": {
"/app": ""
},
tmpfs mounts 可選選項(xiàng)

一個(gè)例子:
docker run -d \ -it \ --name tmptest \ --mount type=tmpfs,destination=/app,tmpfs-mode=1770 \ nginx:latest
tmpfs mounts使用場(chǎng)景
請(qǐng)參考這篇文章:Docker數(shù)據(jù)存儲(chǔ)總結(jié)
參考文章
https://docs.docker.com/storage/tmpfs/
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)本站的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信