Docker Compose:哪种语法产生绑定安装,哪个产生卷

在Docker Compose文档here中,您具有与docker-compose.yml文件的volumes部分相关的以下示例:

  # (1) Just specify a path and let the Engine create a volume
  - /var/lib/mysql

  # (2) Specify an absolute path mapping
  - /opt/data:/var/lib/mysql

  # (3) Path on the host, relative to the Compose file
  - ./cache:/tmp/cache

  # (4) User-relative path
  - ~/configs:/etc/configs/:ro

  # (5) Named volume
  - datavolume:/var/lib/mysql


每当您在注释中看到“体积”时,它将为create a volume:所以(1)和(5).

如果注释中没有卷,则大约为a bind mount.

documentation regarding volumes in docker-compose is here

Mount host paths or named volumes, specified as sub-options to a service.

You can mount a host path as part of a definition for a single service, and there is no need to define it in the top level volumes key.

But, if you want to reuse a volume across multiple services, then define a named volume in the 07004.

The top-level 07005 key defines a named volume and references it from each service’s volumes list. This replaces volumes_from in earlier versions of the Compose file format. See 07006 and 07007 for general information on volumes.

转载注明原文:Docker Compose:哪种语法产生绑定安装,哪个产生卷 - 代码日志