我想知道是否有任何方法可以使用 Dockerfile 将目录从我的主机共享到 docker 容器(共享卷)。
我知道我们可以在使用 docker run 时使用卷(-v 选项)来做到这一点。但是我找不到任何方法可以在使用 Dockerfile 指令时做到这一点。
我已经在 Dockerfile 中尝试过 VOLUME 指令,但没有成功。以下是有关我的环境的一些详细信息:
[me@myHost new]$ tree -L 1
.
|-- docker-compose.yml
|-- Dockerfile
|-- Shared // This is the directory I wish to share with my containers.
`到目前为止,我一直在使用docker-compose.yml文件挂载此目录:
volumes:
- ./Shared:/shared # "Relative Path at the host":"Absolute Path at the container"
但是现在,由于某些原因,我需要将它挂载到Dockerfile 中。我已经尝试了以下但无法成功(它正在 /shared 创建一个新的空卷。):
VOLUME ./Shared:/shared
我可以使用 docker run 并通过在容器中进行手动更改来保存图像,但我希望我是否可以在 Dockerfile 本身中做到这一点。
谢谢。
您无法使用 Dockerfile 中的命令挂载本地目录。你必须这样做docker run
,或代理docker run
喜欢docker-compose
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句