I think you're mixing up variable interpolation in the compose file (that resolves from .env and environment variables) and the environment variables within the container (that you set within the compose file in environment: --that can itself use interpolation-- and env_file:)
So in your exemple, the PORT in the ports: is interpolated from .env (or environment variables), and within your containers each will have a PORT with the values from the env_files.
Those are separate, the .env variables will never leak into the containers unless you explicitly ask for it (using a - PORT in environment:, or using the .env as an env_file, or interpolation in any of those)
BTW, is there any reason you're still using Compose v1⁉️
Yes, thanks for pointing out. You are absolutely right and I came back here to confess my confusion.
Compose v1? Hmm, I was not aware of v2. So far I am doing well with v1 but I will move over to v2 since v1 will no longer receive updates.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I think you're mixing up variable interpolation in the compose file (that resolves from
.env
and environment variables) and the environment variables within the container (that you set within the compose file inenvironment:
--that can itself use interpolation-- andenv_file:
)So in your exemple, the
PORT
in theports:
is interpolated from.env
(or environment variables), and within your containers each will have aPORT
with the values from theenv_file
s.Those are separate, the
.env
variables will never leak into the containers unless you explicitly ask for it (using a- PORT
inenvironment:
, or using the.env
as anenv_file
, or interpolation in any of those)BTW, is there any reason you're still using Compose v1⁉️
Yes, thanks for pointing out. You are absolutely right and I came back here to confess my confusion.
Compose v1? Hmm, I was not aware of v2. So far I am doing well with v1 but I will move over to v2 since v1 will no longer receive updates.