Skip to content
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

[BUG] False "variable is not set" warning when using the ${A:+} interpolation syntax #12637

Open
SpecLad opened this issue Mar 14, 2025 · 3 comments
Labels

Comments

@SpecLad
Copy link

SpecLad commented Mar 14, 2025

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

  1. Create compose.yml as follows:

    services:
      test:
        environment:
          A: ${A:+${A},}B
        image: busybox
        command: ['sh', '-c', 'echo "$$A"']
  2. 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'
B

The -u option prohibits interpolating undefined variables, but no error is produced.

@ndeloof
Copy link
Contributor

ndeloof commented Mar 14, 2025

bash variable support is way more elaborated that compose one 😅
also, AFAICT bash never warn you about empty variable, just defaults to blank, so the comparison is pretty limited here.
What is the actual use-case that revealed this limitation ? Your example is easily replaceable with a default value in variable

@SpecLad
Copy link
Author

SpecLad commented Mar 14, 2025

This is the actual use case - I want the end result to be ${A},B when A is set, and B when it isn't. It's not solvable with just a default value, since the comma should not be present when A is undefined.

@SpecLad
Copy link
Author

SpecLad commented Mar 14, 2025

also, AFAICT bash never warn you about empty variable, just defaults to blank, so the comparison is pretty limited here.

Yeah, there's no warning, but there's an option to make it an error, so I thought it would be a fair comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants