-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested variable interpolation in compose files is not working #4265
Comments
Looks like you have some code about this issue. Feel free to open a PR. |
This allows for nested variables interpolation. Fixes docker#4265 Signed-off-by: N. Le Roux <[email protected]>
This allows for nested variables interpolation. Fixes docker#4265 Signed-off-by: N. Le Roux <[email protected]>
@bsousaa Thanks, done. Struggled a bit figuring out how to deal with the |
Nested interpolation is not supported by docker (docker/cli#4265). Changed the file so that it uses `CUSTOM_TAG` or `ERPNEXT_VERSION` if that's not available.
Nested interpolation is not supported by docker (docker/cli#4265). Changed the file so that it uses `CUSTOM_TAG` or `ERPNEXT_VERSION` if that's not available.
Hi all, This is still an issue in 27.4.0. Technically I think the PR (#4268) just needs another approval, though I'm sure it's far out of date by now. If it makes any difference in terms of priority, the $ ls -a
./ ../ docker-compose.yml
$ cat docker-compose.yml
services:
myservice:
image: alpine:3.18
command: ["/bin/echo","The value of $$FOO is '$FOO'."]
environment:
# Propagate $FOO if set, else use $BAR
- FOO=${FOO:-${BAR}}
$ FOO="baz" docker compose run --rm myservice
time="2025-01-08T23:11:09-05:00" level=warning msg="The \"BAR\" variable is not set. Defaulting to a blank string."
The value of $FOO is 'baz'.
$ FOO="baz" BAR="qux" docker compose run --rm myservice
The value of $FOO is 'baz'.
$ BAR="qux" docker compose run --rm myservice
time="2025-01-08T23:11:27-05:00" level=warning msg="The \"FOO\" variable is not set. Defaulting to a blank string."
The value of $FOO is ''. Of note, changing my compose file to match Frappe's workaround referenced above (i.e., changing And if this makes any difference in terms of priority, here's a cute animal that happens to be the world's most effective feline predator. (Seriously.) Thanks for any attention this could get. |
This allows for nested variables interpolation. Fixes docker#4265 Signed-off-by: N. Le Roux <[email protected]>
This allows for nested variables interpolation. Fixes docker#4265 Signed-off-by: N. Le Roux <[email protected]>
This allows for nested variables interpolation. Fixes docker#4265 Signed-off-by: Gilbert Gilb's <[email protected]>
This allows for nested variables interpolation. Fixes docker#4265 Signed-off-by: N. Le Roux <[email protected]>
It was out of date indeed. But I've just rebased it. |
Description
Interpolation of nested variables in compose files is not supported/bugged.
Reproduce
docker swarm init
HELLO=hello docker stack deploy --compose-file docker-compose.yml foo
docker service logs foo_my-service
The logs print
hello}
, meaning that the variable wasn't properly interpolated.Note that as per compose specification, this should be allowed and is not undefined behavior.
Expected behavior
Either interpolate to
hello
, just like Compose does, or at least output an error such asnested variables interpolation is not supported
. Currently, the interpolation is incorrect which is confusing and surprising to the user.docker version
Client: Version: 23.0.5 API version: 1.42 Go version: go1.20.4 Git commit: bc4487a59e Built: Tue May 2 21:53:09 2023 OS/Arch: linux/amd64 Context: default Server: Engine: Version: 23.0.4 API version: 1.42 (minimum version 1.12) Go version: go1.20.3 Git commit: cbce331930 Built: Fri Apr 21 22:05:37 2023 OS/Arch: linux/amd64 Experimental: false containerd: Version: v1.7.0 GitCommit: 1fbd70374134b891f97ce19c70b6e50c7b9f4e0d.m runc: Version: 1.1.7 GitCommit: docker-init: Version: 0.19.0 GitCommit: de40ad0
docker info
Additional Info
The problem originates from the fact that the parser is regex based, which is not well suited for recursive parsing.
One solution could to write a custom tokenizer/parser, produce an AST and all that jazz. However, Compose already has a working implementation in compose-spec/compose-go. It can be used as a drop-in replacement for the custom
template
module used by this project. I don't know if this solution is acceptable, but if it is, I can draft a PR.Here is a minimal patch that can make this work:
fix_interpolation.patch
As you can see, there's not a lot to it.
The text was updated successfully, but these errors were encountered: