Docker Community Forums

Share and learn in the Docker community.

Docker stack deploy with context and env variables?

I have a docker-compose stack that I have been successfully deploying with

docker --context remote_name stack deploy -c compose-file.yaml stack_name

This works fine and env variables I include via “env_file: .env.web” are correctly used in the deployment. However, I’d like to make use of docker-compose variable substitution to change a couple of items in the yaml based on an “.env” file contents. The .env file is in the directory I run the above command from (that also contains the yaml file).

I expected to be able to use ${VAR_NAME} in the compose file, just as I can when using “docker-compose up”, however when using a stack deploy variable substitution does not appear to take place.

Is this supposed to work when using a stack deploy with a --context?

Ignore above question. Found a mention buried in the docs that .env isn’t used by stack deploy. Further search then turned up a thread about this issue and in particular this comment https://github.com/moby/moby/issues/29133#issuecomment-442912378 that suggests a workaround.