3

Is it possible to substitute (without the use of external tools like envsubst) values in an environment file used in docker-compose (using env_file) with values on a .env file in the folder?

Say I have this .env file:

REGISTRY=something
TAG=something-else

Now in my docker-compose.yml I can have:

# ...
   my_service:
      environment:
        - USE_IMAGE:${REGISTRY}/my_image:${TAG}
# ...

What I'd like is having a different environment file (say, myservice.env), like this:

USE_IMAGE=${REGISTRY}/my_image:${TAG}

And use it on the compose file like:

# ...
   my_service:
      env_file:
        - myservice.env
# ...

However by default, docker-compose (which is the one reading the .env file) doesn't seem to be substituting anything on the other files and I get the literal value.

Is there a way to do this without requiring to have a "rendered" file, directly with docker compose?

I understand I could make a script to pre-process those files using envsubst or something similar, but I'm trying to find a solution without that

Jcl
  • 131
  • 3

0 Answers0