I have the following example files
docker-compose.yml
version: '3' services: web: image: webapp:${VARIABLE_A:-${VARIABLE_B}} env.conf
VARIABLE_B=123 VARIABLE_A is not set on purpose so it should fall back to VARIABLE_B
Docker compose is able to resolve the default value of the environment variable, however docker stack deploy is unable to do the same resolution
user@laptop:~$ docker compose --env-file ./env.conf convert name: dockercomposetest services: web: image: webapp:123 networks: default: null networks: default: name: dockercomposetest_default user@laptop:~$ env $(cat ./env.conf | xargs) docker stack deploy --compose-file docker-compose.yml stack Creating service stack_web failed to create service stack_web: Error response from daemon: rpc error: code = InvalidArgument desc = ContainerSpec: "webapp:${VARIABLE_B}" is not a valid repository/tag As you can see when using docker stack deploy it detects ${VARIABLE_A:-${VARIABLE_B}} is an environment variable that, because VARIABLE_A is not set, it should default to ${VARIABLE_B} however it does not resolve its value which is 123
Obviously, webapp does not exist, it's only an example, but the above error output should be this instead
user@laptop:~$ env $(cat ./env.conf | xargs) docker stack deploy --compose-file docker-compose.yml stack Creating service stack_web failed to create service stack_web: Error response from daemon: rpc error: code = InvalidArgument desc = ContainerSpec: "webapp:123" is not a valid repository/tag Why does this happen? Is there any workarounds for this?