No no, I’m not expecting to get $$VAR substituted within config, it’s just there to show you that Environment variables are actually correctly crafted as a command that will be interpretated later on by the container environment.
Yes this exemple using bash is for the working ubuntu based container and yes everything works according to the spec:
The docker-compose build the command with the appropriate escape character that it then used by bash to substitute it with the inner environment vars filled within the ENV section.
The output is then correct with an echo showing: 192.168.1.74:9090
Prometheus team answered me, they’re endpointing the container directly to /bin/prometheus without any appropriate terminal context, meaning that it’s not expected to substitute anything correctly.
Weird thing is, how is it working using the --env-file flag where this flag is doing the exact same thing than env_file config directive?
EDIT:
OK, I thing I find out what’s going on in here.
We’re in a very specific situation where the prometheus container is build without any terminal, it means that it can’t substitute escaped variables as bash would do.
So, this doesn’t work when:
You create a docker-compose with env_file providing variables to the inner container that are also used to build the command directive.
You create a docker-compose with env_file providing variables to the inner container that are used as is without escape by the command directive to build the final container CMD instruction as docker-compose CLI terminal context don’t have the variables available.
So it work when:
You create a docker-compose and use --env-file to provide the variables as the docker-compose CLI is then creating the variables temporarily within it’s terminal context and then use them to build the not escaped command, that once it’s use by docker as the final CMD instruction is provided to the container ALREADY substituted.
So all in all, it work as intended from the docker part of the issue, what’s completely broken in here is prometheus container that doesn’t provide any terminal context and so can’t really use variables substitution even if the ENV container variable is perfectly filled.
What’s really really weird with their container is that it almost work as the prometheus container succesfully translate the first part of the command…