Docker-compose, conditional statements? (e.g. add volume only if condition)

后端 未结 6 1697
野趣味
野趣味 2021-02-12 02:25

I want to add a volume to my service, but only if the final user gave a folder for it. Otherwise, no volume should be mounted, for the already-prepared image has valid data in a

6条回答
  •  盖世英雄少女心
    2021-02-12 03:16

    Nothing like this currently exists. Options to implement this that I can come up with include:

    1. Make lots of compose file pieces, and merge together the parts you need to build up the final file.

    2. Dynamically generate your compose file. Something like jsonnet may be a good starting point.

    3. Skip compose, and just dynamically generate your docker run command. This starts to lack portability but some use cases are just easier to script yourself.

    4. Submit a PR to the compose and docker/cli github repos to extend the compose functionality. Doing this with a golang template syntax would make the most sense to me.

提交回复
热议问题