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
Using conditional stmts in docker-compose is somewhat possible. Checkout variable substitution. The documentation is available for just the simplest of if-else. And since I have not tried with complex expressions involving strings, I cannot be sure. But following are the points you might want to keep in mind when trying out conditional variables:
env_file
option. Variables in this file are exported in the docker container before the variables under environment
option. That means variables in environment
will override variables in env_file
.