25

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.

据我host-dir所知,使用 Dockerfile 时无法指定或 rw/ro 状态。

除了想与其他容器共享之外,docker 文件中是否还有其他用途?

4

1 回答 1

27

Dockerfile 旨在实现可移植和共享。host-dir 卷是 100% 依赖于主机的,并且会在任何其他机器上中断,这有点偏离 Docker 的想法。

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

Dockerfile 中 VOLUME 的一个常见用途是存储配置或网站源,以便稍后可以由另一个容器更新。

于 2013-09-18T23:28:21.857 回答