-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
compose-spec/compose-go
#847Labels
Description
Description
When a variable interpolation is nested inside a ${A:+}-style interpolation construct for the same variable, compose emits a "variable is not set" warning, even though the nested evaluation isn't supposed to be evaluated.
Steps To Reproduce
-
Create
compose.ymlas follows:services: test: environment: A: ${A:+${A},}B image: busybox command: ['sh', '-c', 'echo "$$A"']
-
Run
docker compose up. It prints the following:WARN[0000] The "A" variable is not set. Defaulting to a blank string. [+] Running 1/1 ✔ Container docker-compose-repro-test-1 Recreated 0.1s Attaching to test-1 test-1 | B test-1 exited with code 0
The warning is a false positive: the nested ${A}, expression should only be evaluated if A is defined, which it isn't.
Compose Version
Docker Compose version v2.33.1
Docker Environment
Client: Docker Engine - Community
Version: 28.0.1
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.21.1
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.33.1
Path: /usr/libexec/docker/cli-plugins/docker-compose
scout: Docker Scout (Docker Inc.)
Version: v1.14.0
Path: /home/dpb/.docker/cli-plugins/docker-scout
Server:
Containers: 3
Running: 1
Paused: 0
Stopped: 2
Images: 242
Server Version: 28.0.1
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: bcc810d6b9066471b0b6fa75f557a15a1cbf31bb
runc version: v1.2.4-0-g6c52b3f
init version: de40ad0
Security Options:
seccomp
Profile: builtin
Kernel Version: 5.15.133.1-microsoft-standard-WSL2
Operating System: Ubuntu 24.04.2 LTS
OSType: linux
Architecture: x86_64
CPUs: 12
Total Memory: 11.68GiB
Name: [redacted]
ID: ded0336a-e1e9-4025-8553-4b4392a16670
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
::1/128
127.0.0.0/8
Live Restore Enabled: false
WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
Anything else?
For comparison, in bash an equivalent scenario works as expected:
$ bash -u -c 'echo ${A:+${A},}B'
BThe -u option prohibits interpolating undefined variables, but no error is produced.