Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (12.7k points)
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 default folder.

That is, I want to do something like; pseudocode:




      if ${VARIABLE} => ${VARIABLE}:/app/folder

Is establishing such a conditional statement doable and definable in a docker-compose file? The only way I see to make this possible is to first define a base docker-compose file, which does not have the volume mount, and the call on a second docker-compose file only if the $VARIABLE is defined. This is fine for a single or few conditions, but gets nasty if there are many.

Any solution?

1 Answer

0 votes
by (29.5k points)
I don't think such things exist as of right now ,one work around that i can think of is

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

Browse Categories