1.5 - Make COMPOSE_PROJECT_NAME accessible to environment
Problem
Given that: - containers join the network under their container name - at least for now - container names depends on the project name I think we need a quick basic solution for 1.5 to allow docker-compose with `--x-networking` enabled to work on a project independently from the project name. The reasoning: project names are variable (they can be different for two users depending on their directory, or can be changed in the CLI). So without forcing the project name, when we up a project, we have no way yet to predict the network name - and worse, no way to predict the hostnames of the other containers in the project. Proposed solution I understand that nice solutions are planned for 1.6, but in the mean time I think we need a solution doable for 1.5. I suggest to set and make the environment variable `COMPOSE_PROJECT_NAME` available. This way we can actually predict at which hostname other containers will be accessible in the current network. Something like `${COMPOSE_PROJECT_NAME}_redis_1`. Example What you do now [code block] [code block] Proposal The proposal is to make that possible: [code block] [code block]
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: 1.5 - Make COMPOSE_PROJECT_NAME accessible to environment
Well IMO there are 2 things at play here: 1. This point is not actually related to networking. To be honest, after reading the doc I kinda expected `COMPOSE_PROJECT_NAME` to be accessible in all cases. Why wouldn't it be? Doesn't this feel more coherent than making it accessible _only if set manually in the CLI_? The current behavior seemed confusing to me until I read the source code. 2. That be
Trust Score
4 verifications
- 1
Well IMO there are 2 things at play here:
1. This point is not actually related to networking. To be honest, after reading the doc I kinda expected `COMPOSE_PROJECT_NAME` to be accessible in all cases. Why wouldn't it be? Doesn't this feel more coherent than making it accessible _only if set manually in the CLI_? The current behavior seemed confusing to me until I read the source code. 2. That being said, using this feature in networking to do what I want to do is indeed going to be useful only for 1 release, you're right.
- 2
But to me it is necessary as right now, I'm struggling to find _any_ way to solv
But to me it is necessary as right now, I'm struggling to find _any_ way to solve my problem in docker-compose with networking: running 2 times the same project with the same docker-compose on the same docker engine but with different networks. Think master + development branches for example.
- 3
So I would argue that given that it makes the environment variables behave more
So I would argue that given that it makes the environment variables behave more coherently and it does not seem to hurt, temporarily solving my scenario is just a bonus. :)
Validation
Resolved in docker/compose GitHub issue #2294. Community reactions: 7 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep