$ docker compose -f 2.yml config
invalid interpolation format for services.workaround.volumes.[].source.
You may need to escape any $ with another $.
${COMPOSER_HOME
$ docker compose -f 1.yml config
name: tmprzkaunqtkf
services:
composer:
image: composer/composer
blabla...
Summing up
$ docker compose -f 2.yml config # not works
$ docker compose -f 1.yml config # works
As for how the variables are interpolated, when extending a service, the interpolated variables will be taken from the extending (not extended) file’s directory
Meaning, if you have 1.yml and 2.yml in different directories, they will interpolate the variables from different .env files
Currently, your files are in the same directory, but keep ti in mind in case you change your folder structure
$ cat 1.yml
services:
composer:
image: composer/composer
volumes:
- ${COMPOSER_HOME:-$$HOME/.config/composer}:/tmp
$ docker compose -f 2.yml config
invalid interpolation format for services.workaround.volumes.[].source.
You may need to escape any $ with another $.
${COMPOSER_HOME
Actually, now that I’m running the code on my computer
I was wrong with the first answer, the single $ is correct, both are interpolated variables
As for the error you’re experiencing, unfortunately, I was able to successfully run the first version of your files, as you uploaded them initially, and it worked
$ tree -a
├── 1.yml
└── 2.yml
$ cat 1.yml
services:
composer:
image: composer/composer
volumes:
- ${COMPOSER_HOME:-$HOME/.config/composer}:/tmp
$ cat 2.yml
services:
workaround:
extends:
file: 1.yml
service: composer
$ docker compose -f 2.yml config
invalid interpolation format for services.workaround.volumes.[].source.
You may need to escape any $ with another $.
${COMPOSER_HOME
Which shows something similar to what you see in your error message
- source: ${COMPOSER_HOME
Which is an invalid reference. The colon separates the source and the target but your syntax uses a colon which is interestingly interpreted well on my machine but not when I use this no-interpolate flag. I guess there was a bug which was fixed in my version but still gives an invalid output with the flag. So you can use the long syntax in 1.yml
Even with this syntax, the no-interpolate flag wil result an incorrect output, but I remember that is an old issue which I attempted to fix as well when I tried to contribute in the compose code but seemed hard to fix. The final output without the flag should be correct though.
Then it is also possible that they introduced a new bug, but I recommend using the long syntax anyway. That way you can make sure it will not create a new folder when you accidentally set a wrong filepath or folder path as source. That behavior can be enabled optionally, but by default it refuses to create the project if the source does not exist.
bind: Used to configure additional bind options:
create_host_path: Creates a directory at the source path on host if there is nothing present. Compose does
nothing if there is something present at the path. This is automatically implied by short syntax for backward compatibility with docker-compose legacy.
`
It was related to the changed syntax from short to long so whether it matters to you or not, could be important to know for anyone who visits this topic. And I wrote it as a reply to your version number and the fact that maybe this bug was introduced in that version. If it is true, even if it is fixed in the future, it is better to keep the long syntax.