在配置docker-compose.yml时,我可以轻松地挂载一个卷,将文件夹从主机映射到容器:
...
volumes:
- "/host/folder/:/container/folder/"
...但是,如果我尝试使用长语法,则不再起作用:
...
volumes:
- type: volume
source: /host/folder
target: /container/folder/
...根据文档
源:挂载的来源、绑定挂载主机上的路径或在顶级卷键中定义的卷的名称。不适用于tmpfs安装。
因此,在长语法中,我似乎必须使用绑定类型来挂载主机路径。这是否有意义,不同的特点,根据语法?
此外,根据文档的说法,
卷是持久化由Docker容器生成和使用的数据的首选机制。绑定挂载依赖于主机的目录结构和操作系统,卷则完全由Docker管理。
所以,我更喜欢有卷而不是绑定。我必须使用简短的语法吗?
发布于 2022-01-21 14:06:24
type:字段显示它是名为volume、bind挂载还是其他一些东西。因为要挂载主机目录,所以需要在扩展语法中指定type: bind。
volumes:
- type: bind # <-- not "volume"
source: /host/folder
target: /container/folder/根据文档,“卷.优先.”
IMHO,Docker文档非常热衷于命名数量和掩盖它们的缺点。由于您无法从Docker外部访问指定卷的内容,因此它们很难备份和管理,并且与注入配置文件和查看日志等任务不匹配。我不会自动找到一个指定的卷,因为Docker文档表明它是首选的。
version: '3.8'
services:
some-application:
volumes:
# Use a bind mount to inject configuration files; you need to
# directly edit them on the host
- type: bind
source: ./config
target: /app/config
# Use a bind mount to read back log files; you need to read them
# on the host
- type: bind
source: ./log
target: /app/data
# Use a named volume for opaque application data; you do not
# need to manipulate files on the host, and on MacOS/Windows
# a named volume will be faster
- type: volume
source: app-data # when type: volume, this is a volume name
target: /app/data
# Do not mount anything over /app or the code in the image.
volumes:
app-data:发布于 2022-01-21 13:39:44
试试这个:
...
services:
some-service:
image: some-image
volumes:
- my-volume-name:/some-path-in-container
volumes:
my-volume-name:
driver: local
driver_opts:
type: 'none'
o: 'bind'
device: '/my-host-folder'
...https://stackoverflow.com/questions/70798717
复制相似问题