Docker Swarm with image versions externalized to .env file Docker Swarm with image versions externalized to .env file docker docker

Docker Swarm with image versions externalized to .env file


The yaml parser in docker stack deploy doesn't have all the same features of that in docker-compose. However, you can use docker-compose config to output a yaml file after it's done all the variable substitutions, extending other files, and merging multiple files together. This effectively turns docker-compose into a preprocessor.


The answer is quite simple: it's not a bug, nor a feature. .env is not currently supported by docker stack.You must source manually the .env running export $(cat .env) before running docker stack ...

There is an issue discussing this needs in the Docker Github.https://github.com/docker/docker.github.io/issues/3654and another one discussing the problem and solution: https://github.com/moby/moby/issues/29133#issuecomment-285980447


As already mentioned the .env isn't currently supported by the docker stack.So the alternative way is to clearly specify the environment file using by env_file, e.g.:

version: '3.3'services:  foo-service:    image: foo-image    env_file:      - .env    environment:      - SOME_ENV=qwerty