简体   繁体   中英

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

I have a docker-compose.yml file like this:

  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:

  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. An example of these are in this presentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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