英文:
How to create tmpfs folder with Docker via volume instruction?
问题
我想通过Dockerfile中的Docker指令创建tmps卷。这是否可行?是否有其他参数可以传递以配置卷指令?
英文:
I want to create tmps volume via docker instructions in dockerfile. Is it possible to do so? Are there additional parameters which I can pass to configure volume instruction?
答案1
得分: 0
以下是关于如何为 tmpfs 卷进行仪表化的官方文档,以及其中的一个简单示例:
docker run -d \
-it \
--name tmptest \
--mount type=tmpfs,destination=/app \
nginx:latest
相反,这个链接告诉您如何通过Docker Compose执行相同的操作:
type: tmpfs
target: /app
tmpfs:
size: 1000
英文:
Here is the Official documentation about how to instrument a tmpfs volume, and here a simple example from there:
docker run -d \
-it \
--name tmptest \
--mount type=tmpfs,destination=/app \
nginx:latest
Instead this link tells you how to do the same thing by Docker Compose:
type: tmpfs
target: /app
tmpfs:
size: 1000
答案2
得分: 0
在Dockerfile中,你几乎无法指定有关卷或其他类型的运行时配置的几乎任何信息。特别是没有办法指示容器应始终运行并挂载tmpfs。
有关运行时卷的唯一真正的Dockerfile语句是VOLUME
指令。它没有配置,只有一个必须在其上挂载某种卷的目录列表。它的直接效果是在该目录上挂载一个匿名卷,如果没有其他内容的话;其间接效果是防止将来的RUN
指令修改该目录。你几乎不需要它。
@AntonioPetricca的答案显示了一个docker run --mount type=tmpfs
选项,如果你想要将tmpfs容器挂载到另一个容器中,那么在创建它时 必须 指定这个选项(或等效的Compose)。目标目录不需要是VOLUME
目录。在Dockerfile中没有强制此选项的方法。
在更有限的范围内,你可以使用RUN --mount=type=tmpfs,target=/directory
来运行单个Dockerfile构建步骤。再次强调,命名目录不会在镜像中持久存在。挂载不会超出单个RUN
命令的范围。
英文:
In a Dockerfile, you can specify almost nothing about volumes or several other types of runtime configuration. In particular there is no way to indicate a container should always run with a tmpfs mounted.
The only real Dockerfile statement about volumes at runtime is the VOLUME
directive. It has no configuration, only a list of directories that must have some sort of volume mounted on them. Its direct effect is to cause an anonymous volume to be mounted on that directory if nothing else is; its indirect effect is to prevent future RUN
directives from modifying the directory. You rarely if ever need it.
@AntonioPetricca's answer shows a docker run --mount type=tmpfs
option, and if you want to mount a tmpfs container into an container, you must specify this (or a Compose equivalent) when you create it. The target directory does not need to be a VOLUME
directory. There is no way to force this option in the Dockerfile.
In a more limited scope, you can run an individual Dockerfile build step with RUN --mount=type=tmpfs,target=/directory
. Again, the named directory won't be persisted in the image. The mount won't last beyond that single RUN
command though.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论