[BUG] -p
(aka --project-name
) does not override the interpolated value of COMPOSE_PROJECT_NAME
if COMPOSE_PROJECT_NAME
is present in the environment or .env
file
#11734
Labels
Description
When
-p
(aka--project-name
) is explicitly passed todocker compose
andCOMPOSE_PROJECT_NAME
is also present in the environment or.env
file, then Docker Compose will use the value from--project-name
as a name of the project, but would interpolateCOMPOSE_PROJECT_NAME
using the value from the environment or the.env
file.Steps To Reproduce
compose.yaml
:.env
:docker compose config
:Note that
foo
is used as the project name and as a prefix in volume'sname:
.4. Run
docker compose --project-name bar config
:Notice that
bar
is used as the project name, but volume's name is still prefixed withfoo
- this is a bug.Compose Version
Docker Environment
Anything else?
It is correct that the value of
--project-name
takes precedence overCOMPOSE_PROJECT_NAME
, see the docs here and here.But it does not feel right that interpolation of
COMPOSE_PROJECT_NAME
follows the same logic as for a regular variable. Given thatCOMPOSE_PROJECT_NAME
is a predefined variable with a special meaning, its interpolation should take the value of--project-name
into account.This is not directly related to a bug report, but I would like to share some background story for a better context.
I am working on a project using PostgreSQL. Docker Compose is used to run development environment. Docker volume is mounted into container to persist DB data between container restarts. The format of these data is dependent on the major version of PostgreSQL, container fails to start if data in the volume is not compatible. In case of PostgreSQL version bump this requires developers to manually delete the volume.
My idea was to "version" the volume together with PostgreSQL image and force Docker Compose to create a new volume for the database in case of a major version bump since the development database is ephemeral anyway. The only way to use variable in volume's name is to use
name:
, because keys of the top-levelvolumes:
mapping are not interpolated. Butname:
is not automatically project-scoped, hence there is a need to explicitly useCOMPOSE_PROJECT_NAME
as a prefix.COMPOSE_PROJECT_NAME
is set in.env
file, because Compose file is located inside a nested directory within the project, and otherwise the project wouldn't have a meaningful name. Finally,--project-name
is also set, because we are using Visual Studio Code and Dev Containers extension and--project-name
value differs fromCOMPOSE_PROJECT_NAME
in.env
file because of a bug in Dev Containers extension.The text was updated successfully, but these errors were encountered: