简体   繁体   English

将卷挂载作为外部文件传递 (docker-compose)

[英]Pass volume mounts as an external file (docker-compose)

I have a docker-compose.yml file like this:我有一个这样的 docker-compose.yml 文件:

  name:
    image: docker/container
    container_name: coolcontainer
    restart: always

    volumes:
      - ${DIR1PATH}:/storage/${DIR1}
      - ${DIR2PATH}:/storage/${DIR2}
      - ${DIR3PATH}:/storage/${DIR3}
      - ${DIR4PATH}:/storage/${DIR4}

Is it possible to store all the volume mounts in a separate file so that the docker-compose.yml can be replaced with:是否可以将所有卷安装存储在一个单独的文件中,以便 docker-compose.yml 可以替换为:

  name:
    image: docker/container
    container_name: coolcontainer
    restart: always

    volumes:
      ${CUSTOM_MOUNTS_FILE}

Not specifically like you've requested, but you can merge multiple compose files together.不是特别像您要求的那样,但您可以将多个撰写文件合并在一起。 One of those files could include your additional volumes while the first one is just your service definition.其中一个文件可能包含您的附加卷,而第一个文件只是您的服务定义。 Your second file would look like:你的第二个文件看起来像:

version: '3'
services:
  name:
    volumes:
      - ${DIR1PATH}:/storage/${DIR1}
      - ${DIR2PATH}:/storage/${DIR2}
      - ${DIR3PATH}:/storage/${DIR3}
      - ${DIR4PATH}:/storage/${DIR4}

There are also extension fields in compose that allow you to define values, and then use yaml anchors and aliases to inject a value. compose 中还有扩展字段,允许您定义值,然后使用 yaml 锚点和别名来注入值。 An example of these are in this presentation . 本演示文稿中提供了其中一个示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM