我可以指定从Dockerfile挂载的主机目录

Docker运行命令有选项将主机目录挂载到容器中

-v=[]: Create a bind mount with: [host-dir]:[container-dir]:[rw|ro]. If "host-dir" is missing, then docker creates a new volume. 

而Dockerfile有VOLUME指令

 VOLUME ["/data"] - The VOLUME instruction will add one or more new volumes to any container created from the image. 

从我所看到的,在使用Dockerfile时,没有办法指定host-dir或rw / ro的状态。

在docker文件中是否有任何其他用法VOLUME除了想与其他容器共享?

Dockerfiles意味着可移植和共享。 主机目录容量是100%的主机相关的东西,并会打破任何其他机器,这是一点点的Docker的想法。

因此,只能在Dockerfile中使用便携式指令。 如果您需要主机目录卷,则需要在运行时指定它。

Dockerfile中VOLUME的常见用法是存储configuration或网站资源,以便以后可以由其他容器更新。