Skip to content

Commit 62d5fcd

Browse files
committed
Add detailed project name requirements, mechanisms
These changes reflect current `docker compose` behavior regarding acceptable project names. compose-spec/compose-go#261 changed `docker compose` behavior to require normalized project names as input, instead of normalizing project names automatically. This landed in compose-spec/compose-go v1.2.5 and docker/compose v2.5.1. compose-spec/compose-spec#314 updated the compose spec, and compose-spec/compose-go#362 added information to the error message specifying the correct project name format. Local development URLs: - http://localhost:4000/compose/reference/#use--p-to-specify-a-project-name - http://localhost:4000/compose/environment-variables/envvars/#compose_project_name - http://localhost:4000/engine/reference/commandline/compose/#use--p-to-specify-a-project-name Production URLs: - https://docs.docker.com/compose/reference/#use--p-to-specify-a-project-name - https://docs.docker.com/compose/environment-variables/envvars/#compose_project_name - https://docs.docker.com/engine/reference/commandline/compose/#use--p-to-specify-a-project-name Signed-off-by: Mike Bland <[email protected]>
1 parent 9a91ee7 commit 62d5fcd

3 files changed

Lines changed: 47 additions & 7 deletions

File tree

_data/compose-cli/docker_compose.yaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,21 @@ long: |-
6363
6464
### Use `-p` to specify a project name
6565
66-
Each configuration has a project name. If you supply a `-p` flag, you can specify a project name. If you don’t
67-
specify the flag, Compose uses the current directory name.
68-
Project name can also be set by `COMPOSE_PROJECT_NAME` environment variable.
66+
Each configuration has a project name. Compose sets the project name using
67+
the following mechanisms, in order of precedence:
68+
69+
- The `-p` command line flag
70+
- The `COMPOSE_PROJECT_NAME` environment variable
71+
- The top level `name:` variable from the config file (or the last `name:`
72+
from a series of config files specified using `-f`)
73+
- The `basename` of the project directory containing the config file (or
74+
containing the first config file specified using `-f`)
75+
- The `basename` of the current directory if no config file is specified
76+
77+
Project names must contain only lowercase letters, decimal digits, dashes,
78+
and underscores, and must begin with a lowercase letter or decimal digit. If
79+
the `basename` of the project directory or current directory violates this
80+
constraint, you must use one of the other mechanisms.
6981
7082
Many Compose subcommands can be run without a Compose file by passing
7183
the project name.

compose/environment-variables/envvars.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,21 @@ the container's name on startup.
4343
For example, if your project name is `myapp` and it includes two services `db` and `web`,
4444
then Compose starts containers named `myapp-db-1` and `myapp-web-1` respectively.
4545

46-
It defaults to the `basename` of the project directory.
46+
Compose sets the project name using the following mechanisms, in order of
47+
precedence:
48+
49+
- The `-p` command line flag
50+
- `COMPOSE_PROJECT_NAME`
51+
- The top level `name:` variable from the config file (or the last `name:` from
52+
a series of config files specified using `-f`)
53+
- The `basename` of the project directory containing the config file (or
54+
containing the first config file specified using `-f`)
55+
- The `basename` of the current directory if no config file is specified
56+
57+
Project names must contain only lowercase letters, decimal digits, dashes, and
58+
underscores, and must begin with a lowercase letter or decimal digit. If the
59+
`basename` of the project directory or current directory violates this
60+
constraint, you must use one of the other mechanisms.
4761

4862
See also the [command-line options overview](../reference/index.md#command-options-overview-and-help) and [using `-p` to specify a project name](../reference/index.md#use--p-to-specify-a-project-name).
4963

compose/reference/index.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,23 @@ Status: Downloaded newer image for postgres:latest
185185

186186
## Use `-p` to specify a project name
187187

188-
Each configuration has a project name. If you supply a `-p` flag, you can
189-
specify a project name. If you don't specify the flag, Compose uses the current
190-
directory name. See also the [COMPOSE_PROJECT_NAME environment variable](../environment-variables/envvars.md#compose_project_name).
188+
Each configuration has a project name. Compose sets the project name using the
189+
following mechanisms, in order of precedence:
190+
191+
- The `-p` command line flag
192+
- The [COMPOSE_PROJECT_NAME environment variable][]
193+
- The top level `name:` variable from the config file (or the last `name:` from
194+
a series of config files specified using `-f`)
195+
- The `basename` of the project directory containing the config file (or
196+
containing the first config file specified using `-f`)
197+
- The `basename` of the current directory if no config file is specified
198+
199+
[COMPOSE_PROJECT_NAME environment variable]: ../environment-variables/envvars.md#compose_project_name
200+
201+
Project names must contain only lowercase letters, decimal digits, dashes, and
202+
underscores, and must begin with a lowercase letter or decimal digit. If the
203+
`basename` of the project directory or current directory violates this
204+
constraint, you must use one of the other mechanisms.
191205

192206
## Use `--profile` to specify one or more active profiles
193207

0 commit comments

Comments
 (0)