问题描述
VOLUME 命令在 Dockerfile (图像构建层)
和
docker run -v / xyz / bla $时, c $ c>命令(容器构建层)。
-v 参数对我来说很清楚,从主机到容器的目录,反之亦然,但是如何在 Dockerfile 中的 VOLUME 的行为方式不同?
-v 参数和 VOLUME 几乎相同。您可以使用 -v 具有与 VOLUME 相同的行为。
docker run -v / data
与
相同VOLUME / data
/ pre>
但是还需要更多的使用哪些是映射卷的地方:
#code> docker run -v data:/ data#命名卷
docker运行-v / var / data:/ data#主机挂载的卷,这是你所指的使用的,但是当你可以看到有更多的用途,
所以问题是:什么是使用 VOLUME 在 Dockerfile ?
容器文件系统由图层组成写入的速度比普通文件系统要慢一些(因为固定的层数)。
你声明 VOLUME 您的 Dockerfile 表示容器将写入应用程序数据的位置。例如,一个数据库容器,它的数据将进入一个卷,而不管你在 docker运行中的内容。
如果您为JBoss创建了docker容器,并且希望使用 libaio 使用快速文件系统访问,则需要将数据目录声明为 VOLUME 或JBoss将在启动时崩溃。
总结 VOLUME 声明一个卷,无论你在做什么码头运营商。实际上,在 docker运行中,您无法撤消 Dockerfile $ c中的 VOLUME 声明$ c>。
感谢
Could some one help me to understand the difference between:
VOLUME command in Dockerfile (image building layer)
and
-v paramter when issuing docker run-v/xyz/bla command (container building layer).
-v parameter is for me clear, it simply exposes a directory from the host to the container and vice versa, but how does VOLUME in Dockerfile behave differently?
解决方案The -v parameter and VOLUME are almost the same. You can use -v to have the same behavior as VOLUME.
docker run -v /dataSame as
VOLUME /dataBut also -v have to more uses which are where map the volume:
docker run -v data:/data # Named volumes docker run -v /var/data:/data # Host mounted volumes, this is what you refer to -v use, but as you can see there are more uses,So the question is: what is the use of VOLUME in a Dockerfile?
The container filesystem is made of layers so writing there is slower and limited (because the fixed number of layers) than the plain filesystem.
You declare VOLUME in your Dockerfile to denote where your container will write application data. For example a database container, its data will go in a volume regardless what you put in your docker run.
If you create a docker container for JBoss and you want to use fast filesystem access with libaio yo need to declare the data directory as a VOLUME or JBoss will crash on startup.
In summary VOLUME declares a volume regardless what you do in docker run. In fact in docker run you cannot undo a VOLUME declaration made in Dockerfile.
Regards
这篇关于Dockerfile中的VOLUME声明与作为docker运行参数的-v之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!