I would expect docker-compose-defined volumes to behave the same way as docker run-defined volumes.
Specifically, I would expect docker-compose-defined volumes to have the name I give them.
Actual Behavior
What actually happens is that the named volume gets prepended with (a simplified version of) the directory name from which the docker-compose command was run.
For instance, if I run from the deployment_root directory, and I name the volume my_named_vol, then I end up with a volume named deploymentroot_my_named_vol.
If this “is not a bug,” please explain the rationale.
Now that I know these things about how it works, I’d like to know why it’s done this way.
If I specify a volume name, that’s the name I want it to have. I don’t want it to arbitrarily have a prefix (whether that’s the completely arbitrary seeming current directory, or whether it’s some contrived prefix I must give it–since -p "" doesn’t seem to work). @tnelis’s external suggestion is good to know about, but I do want docker-compose to set up my volumes.
So what’s the rationale for this project stuff? It seems presumptuous, but maybe I just haven’t stumbled on something that makes it all clear yet.
I personally find it rather useful on our QA boxes we use for CI for example, where we deploy many service compositions of the same codebase. Each uses a different project name so out-of-the-box the volumes never conflict. More generally it also makes them easier to recognize just like every other resource created by docker-compose (networks, containers, …). Not doing it this way would be quite inconsistent IMO.
Depends on the situation, in most cases on development boxes the directory will be a good heuristic. When they aren’t we usually have small scripts we can source to set up the shell environment so we don’t have to type the -p option all the time.
In the case of the CI system I mentioned previously, we really do want to specify the project name explicitly since it will contain a high-entropy string to ensure the name doesn’t conflict. We do this with the COMPOSE_PROJECT_NAME environment variable which is more convenient for us in those procedures, though the semantics are exactly the same as the -p option.
Hi - I’m new to Docker, and would also like to use docker-compose to mount to an existing volume. It’s nice to know that the prefix can be specified via -p. However… where do I do this? on the docker-compose? In docker-compose.yml?