Dockerfile中的VOLUME声明与作为docker运行参数的-v之间的差异 [英] Difference between VOLUME declaration in Dockerfile and -v as docker run parameter
问题描述
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 inDockerfile
(image building layer)and
-v
paramter when issuingdocker 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 doesVOLUME
inDockerfile
behave differently?解决方案The
-v
parameter andVOLUME
are almost the same. You can use-v
to have the same behavior asVOLUME
.docker run -v /data
Same as
VOLUME /data
But 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 aDockerfile
?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 yourDockerfile
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 yourdocker 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 aVOLUME
or JBoss will crash on startup.In summary
VOLUME
declares a volume regardless what you do indocker run
. In fact indocker run
you cannot undo aVOLUME
declaration made inDockerfile
.Regards
这篇关于Dockerfile中的VOLUME声明与作为docker运行参数的-v之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!