DEV Community

Discussion on: docker-compose will always load .env

Collapse
 
tbroyer profile image
Thomas Broyer

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⁉️

Collapse
 
byte4bike profile image
Jonah Yeoh

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.