Skip to content

Add -p/--project-name and docker compose project name resolution - #187

Merged
Mcrich23 merged 2 commits into
Mcrich23:mainfrom
adrum:feat/compose-project-flags
Nov 25, 2026
Merged

Mcrich23 merged 2 commits into
Mcrich23:mainfrom
adrum:feat/compose-project-flags

Conversation

@adrum

@adrum adrum commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

This is #104 ported onto current main — the commit is @w1zdun's, authorship preserved. That PR predates the shared resolution layer (#138), so it patched up, down, and build individually and has been conflict-bound ever since; after #138 the whole feature lands in one place, ComposeProjectOptions.projectName(for:), and every command gets it through the shared options.

What it does: resolves the project name with docker compose's precedence — the -p/--project-name flag, then COMPOSE_PROJECT_NAME (process environment over the .env file), then the compose name: field with ${VAR:-default} interpolation, then the directory name.

It also fixes the bug from the original report: a name: like ${COMPOSE_PROJECT_NAME:-myproj} was previously used literally, producing invalid container names.

w1zdun's test suite came along with the port: nine cases covering each precedence tier, the env-file vs process-env ordering, and the interpolation paths. Verified live: -p wins over name:, COMPOSE_PROJECT_NAME wins over the file, and an interpolated name: resolves before containers are named.

… name resolution

Resolve the project name with the same precedence as docker compose:
-p/--project-name flag > COMPOSE_PROJECT_NAME (process env > .env) >
top-level 'name' field (now with ${VAR:-default} interpolation) >
directory name.

Previously a name like ${COMPOSE_PROJECT_NAME:-myproj} was used
literally, producing invalid container names. ComposeDown also gains
.env file loading so 'down' resolves the same names as 'up'.
@adrum
adrum force-pushed the feat/compose-project-flags branch from 6e1240f to 44bd95b Compare November 14, 2026 19:59
The fallback name came from the process cwd, so up -f <path> and
down -f <path> run from different directories derived different
project names and could not find each other's containers. Derive from
the first compose file's directory instead — stable no matter where
the command runs from, and identical to the old behavior when the
file is discovered in the cwd. Covered by a unit test pinning that
two different --cwd values with the same -f resolve the same name,
and verified live: up from /tmp, down from $HOME, same -f, same
containers.

@Mcrich23 Mcrich23 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@Mcrich23
Mcrich23 merged commit b044818 into Mcrich23:main Nov 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants