I would like to run entire docker container in memory without mapping volumes to host's hard drive.
TMPFS described here helps to mount volumes as "memory volumes", but I'm looking a way how to start entire container mapped to memory.
--volume-driver
probably what I have to use, but I can't find a documented list of supported drivers (not overlay2
).
So, I've tried:
docker run -td --name my-container --volume-driver tmpfs container-image
docker run -td --name my-container --volume-driver memfs container-image
But in both cases, with docker inspect my-container
I observed that:
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/d1d112972c6b531976dd33e27edf213fc578856c3ee96b99c9afe53ad3f71a5e- ... /diff",
"MergedDir": "/var/lib/docker/overlay2/d1d112972c6b531976dd33e27edf213fc578856c3ee96b99c9afe53ad3f71a5e/merged",
"UpperDir": "/var/lib/docker/overlay2/d1d112972c6b531976dd33e27edf213fc578856c3ee96b99c9afe53ad3f71a5e/diff",
"WorkDir": "/var/lib/docker/overlay2/d1d112972c6b531976dd33e27edf213fc578856c3ee96b99c9afe53ad3f71a5e/work"
},
"Name": "overlay2"
}
docker stats
also points me that both cases are using default mapping strategy.
答案 0 :(得分:1)
有一个问题已被关闭以解决。这是评论https://github.com/moby/moby/issues/10490#issuecomment-311892718的链接。
从本质上讲,它配置docker以将图像保存在RAM中。它将执行您想要的操作,但是如果您关闭计算机,则会丢失图像。
现在,我不确定您为什么要这么做,但是我将根据我认为您的需求进行推断:
您不希望在运行容器后进行任何跟踪:然后,添加--rm
标志,该标志将删除将始终创建的文件。这样可以使您的运行保持整洁,但可能并不完全安全。
出于安全原因,您不希望将要写入的任何数据保留在磁盘上:然后,您必须在容器中的某个位置挂载tmpfs(https://docs.docker.com/engine/reference/run/#tmpfs-mount-tmpfs-filesystems),而仅写入那里。请记住,如果使用swap,则内容将被写入磁盘,并且有可能恢复。
您想要快速读取容器中已经存在的数据:那么我认为最好的选择是,当容器启动时,要复制数据,您需要在安装在容器中的tmpfs中快速访问。 / p>
希望我能抓住您的用例并提供帮助,如果没有,请这么说:)