在DockerFile而不是adhoc cmd-line -v中定义VOLUME挂载点的目的是什么? [英] What is the purpose of defining VOLUME mount points within DockerFile rather than adhoc cmd-line -v?

查看:80
本文介绍了在DockerFile而不是adhoc cmd-line -v中定义VOLUME挂载点的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解在Dockerfile中使用VOLUME命令定义了容器中的安装点。

I understand that using the VOLUME command within a Dockerfile, defines a mount point within container.

FROM centos:6
VOLUME /html

但是我注意到,没有该VOLUME定义,仍然可以安装在不管是否定义该VOLUME点

However I noticed that without that VOLUME definition, it's still possible to mount on that VOLUME point regardless of defining it

docker run -ti -v /path/to/my/html:/html centos:6

在dockerfile中定义VOLUME挂载点的目的是什么?我怀疑这是出于可读性,所以人们可以阅读Dockerfile并立即知道要挂载什么内容?

What is the purpose of defining VOLUME mount points in the dockerfile? I suspect it's for readability so people can read the Dockerfile and instantly know what is meant to be mounted?

推荐答案

<$ c $在 Dockerfile 中使用的c> VOLUME 指令不允许我们进行主机挂载,即将主机OS中的目录挂载到容器。

VOLUME instruction used within a Dockerfile does not allow us to do host mount, that is where we mount a directory from the host OS into a container.

但是,其他容器仍可以使用-from-container =<容器名称> ,使用 Dockerfile

However other containers can still mount into the volumes of a container using the --from-container=<container name>, created with the VOLUMES instruction in the Dockerfile

这篇关于在DockerFile而不是adhoc cmd-line -v中定义VOLUME挂载点的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆