New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use COMPOSE_PROJECT_NAME
?
#3431
Comments
I have to do this to work around the issue you have been running into: COMPOSE_PROJECT_NAME=project docker-compose up ... and within my docker-compose.yml file I use the variable with the following syntax: ${COMPOSE_PROJECT_NAME} So essentially I have the same problem that you do, but fortunately this workaround has been serving me well. Note that if you set the variable on a separate line of the script it will not be read... same as setting it in .env as you have noted. I would really like for the -p switch to work, it is much easier to remember and to type! |
It may be worth noting that I'm on Ubuntu 14.04 in this case... I'm curious if the -p switch works on other platforms. |
Where are we on this? Is it solved for you @ryanweal, @Mahmoudz? From
So you have to use the So it's expected that Can you try and see if this solves your problems? Hope this helped :-) |
I could not get the -p switch to work at all. The environment variable only worked if it was passed on the same line as the up command. I could have used an entirely different variable but I'm hoping that this flag will start working at some point. |
Here is what I get when I try the suggested format: What is curious is that it appears to have named the containers correctly in spite of the warning. I've seen it start up boxes with a null value before though, not sure if it was this same syntax or not. So I guess it might work... but with an unexpected warning. |
@ryanweal Yes, it's perfectly normal:
Now for when you use So you have three scenarii :
From what I understand of your last post, it seems that you are setting the project name with Hope this helped! |
Ah, so basically if I need to use a custom variable I'll have to provide the variable twice... once for myself and once for docker-compose. That seems inefficient. I'll stick to setting the COMPOSE_PROJECT_NAME variable in my case then. |
No I don't understand why you would say that if you need to use a custom variable you have to define it twice. It's just that the It's just that you expected that it defined an ENV variable too, named If you need to define, go ahead and do it :-) |
As reported on the forum at https://forums.docker.com/t/unable-to-use-compose-project-name-in-docker-compose/30157, the COMPOSE_PROJECT_NAME nor the -p seem to work in docker-compose 1.10.0. It did work for 1.8.0. |
COMPOSE_PROJECT_NAME is a documented env var. Refer to https://docs.docker.com/compose/reference/envvars/ |
Figured we should stop directing users to an old docker-compose binary. In addition, this switches from the -p flag to COMPOSE_PROJECT_NAME to ensure that environment variable is set. -p behaves the same but does not set the variable. See the following link for more. docker/compose#3431 (comment) Finally, I added the -v flag to docker-compose down, which ensures any automatic volumes are removed when the cluster is stopped.
Figured we should stop directing users to an old docker-compose binary. In addition, this switches from the -p flag to COMPOSE_PROJECT_NAME to ensure that environment variable is set. -p behaves the same but does not set the variable. See the following link for more. docker/compose#3431 (comment) Finally, I added the -v flag to docker-compose down, which ensures any automatic volumes are removed when the cluster is stopped.
Figured we should stop directing users to an old docker-compose binary. In addition, this switches from the -p flag to COMPOSE_PROJECT_NAME to ensure that environment variable is set. -p behaves the same but does not set the variable. See the following link for more. docker/compose#3431 (comment) Finally, I added the -v flag to docker-compose down, which ensures any automatic volumes are removed when the cluster is stopped.
Figured we should stop directing users to an old docker-compose binary. In addition, this switches from the -p flag to COMPOSE_PROJECT_NAME to ensure that environment variable is set. -p behaves the same but does not set the variable. See the following link for more. docker/compose#3431 (comment) Finally, I added the -v flag to docker-compose down, which ensures any automatic volumes are removed when the cluster is stopped.
Just stumbled upon this now. I think what is confusing about this scenario is that setting the
Because The key difference here is that the environment variable is only used for reading by docker compose. It will not be automatically populated. (Contrast that to e.g. CI environment where the environment variables are provided for you to consume.) The current way this works is fine, but I think the documentation could use an explicit warning about this. |
I totally agree with @melkamar. If I want to define any other item (e.g. network names) using the project name as a prefix, the ENV variable is mandatory. Docs are a bit confusing at this point.
|
Thing is, though , the docs say: "If you do not set this, the COMPOSE_PROJECT_NAME defaults to the basename of the project directory." |
Same concern here (v1.29.2) : I was expected when reading the documentation that COMPOSE_PROJECT_NAME will be set to the basename of the project directory but it stays empty. |
The important thing to note is setting This is super useful when I have builds happening for different environments, avoids network and volume name clashes if the builds for different environments happen to run at the same time. |
I would also have liked In my scenario, I have one docker compose file I want to run for two instances of a huge application. I'd much rather use
than
|
Looks like this is going to be fixed in newer versions of docker compose (anything using
|
I'm using the latest version of everything and the v2 of docker compose.
docker-compose.yml
file with no luck as there's no clear reference on where to place it exactly?.env
file but didn't read it!I'm more interested in adding it to the docker-compose file.
The main reason is I want to override the default project name which is the directory name.
The text was updated successfully, but these errors were encountered: