docker-compose 卷版本 3 语法

docker-compose volumes version 3 syntax

docker compose 的第 3 版允许指定卷。虽然我希望以某种方式使用它,但我不确定它是否有效,但有人可以提供一些见解,这就是我正在寻找的内容:

我们有很多应用程序,所以我想在一个地方指定卷区域

volumes:
   app: ./app
   microservice: ./microservice
   anothermicroservice: ./anothermicroservice
   ...

services:
   app:
      ...
      volumes:
         - app/.git:/usr/src/.git
         - app/src:/usr/src/src
   microservice:
      ...
      volumes:
          - microservice/.git:/usr/src/.git
          - microservice/src:/usr/src/src
   ...

这可能吗?或者类似的东西?谢谢

据我所知卷语法不提供它。

但我建议使用 environment variables,例如使用 .env 文件

$ cat .env
APP=./app
MICROSERVICE=./microservice

$ cat docker-compose.yml
services:
  app:
    volumes:
     - $APP/.git:/usr/src/.git
     - $APP/src:/usr/src/src
  microservice:
    volumes:
      - $MICROSERVICE/.git:/usr/src/.git
      - $MICROSERVICE/src:/usr/src/src