Skip to content

Commit c8f4107

Browse files
committed
Fix project name evaluation order
The COMPOSE_PROJECT_NAME environment variable must override the top-level name: attribute in the Compose file. The precedence order is defined in the docker compose documentation https://docs.docker.com/compose/how-tos/project-name/#set-a-project-name Signed-off-by: Ruben Jenster <[email protected]>
1 parent f53a341 commit c8f4107

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

podman_compose.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -1981,15 +1981,20 @@ def _parse_compose_file(self):
19811981
content = normalize(content)
19821982
# log(filename, json.dumps(content, indent = 2))
19831983

1984+
# See also https://docs.docker.com/compose/how-tos/project-name/#set-a-project-name
1985+
# **project_name** is initialized to the argument of the `-p` command line flag.
19841986
if not project_name:
1985-
project_name = content.get("name")
1986-
if project_name is None:
1987-
# More strict then actually needed for simplicity:
1988-
# podman requires [a-zA-Z0-9][a-zA-Z0-9_.-]*
1989-
project_name = self.environ.get("COMPOSE_PROJECT_NAME", dir_basename.lower())
1990-
project_name = norm_re.sub("", project_name)
1991-
if not project_name:
1992-
raise RuntimeError(f"Project name [{dir_basename}] normalized to empty")
1987+
project_name = self.environ.get("COMPOSE_PROJECT_NAME")
1988+
if not project_name:
1989+
project_name = content.get("name")
1990+
if not project_name:
1991+
project_name = dir_basename.lower()
1992+
# More strict then actually needed for simplicity:
1993+
# podman requires [a-zA-Z0-9][a-zA-Z0-9_.-]*
1994+
project_name_normalized = norm_re.sub("", project_name)
1995+
if not project_name_normalized:
1996+
raise RuntimeError(f"Project name [{project_name}] normalized to empty")
1997+
project_name = project_name_normalized
19931998

19941999
self.project_name = project_name
19952000
self.environ.update({"COMPOSE_PROJECT_NAME": self.project_name})

0 commit comments

Comments
 (0)