aspire icon indicating copy to clipboard operation
aspire copied to clipboard

Disambiguate Docker Compose project names using AppHost path hash

Open Copilot opened this issue 1 month ago • 5 comments

Description

Docker Compose derives project names from the output directory name. When multiple app hosts deploy to the same directory (e.g., aspire-output), they collide and overwrite each other's deployments.

Changes

  • DockerComposeEnvironmentResource: Added GetDockerComposeProjectName() method that incorporates AppHost:PathSha256 into the project name
  • Docker Compose commands: Added --project-name flag to up and down operations
  • Debug logging: Added logging to show the project name and full docker compose command arguments for observability
  • Project name format: aspire-{environmentName}-{first8CharsOfPathSha} (e.g., aspire-docker-compose-abc123de)
  • Fallback: Uses aspire-{environmentName} when PathSha256 unavailable
  • Test: Added test using TestLogger infrastructure to validate the project name generation logic and configuration

Example

Two app hosts deploying to the same output directory now get distinct project names:

// App Host 1: /projects/app1/AppHost/AppHost.csproj
// Project name: aspire-docker-compose-abc123de

// App Host 2: /projects/app2/AppHost/AppHost.csproj  
// Project name: aspire-docker-compose-xyz789gh

// Both can deploy to ./aspire-output without collision

The debug logs will show:

Running docker compose up with project name: aspire-docker-compose-abc123de, arguments: compose -f "..." --project-name "aspire-docker-compose-abc123de" up -d --remove-orphans

Fixes dotnet/aspire#12818

Checklist

  • Is this feature complete?
    • [x] Yes. Ready to ship.
    • [ ] No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • [x] Yes
    • [ ] No
  • Did you add public API?
    • [ ] Yes
      • If yes, did you have an API Review for it?
        • [ ] Yes
        • [ ] No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • [ ] Yes
        • [ ] No
    • [x] No
  • Does the change make any security assumptions or guarantees?
    • [ ] Yes
      • If yes, have you done a threat model and had a security review?
        • [ ] Yes
        • [ ] No
    • [x] No
  • Does the change require an update in our Aspire docs?
Original prompt

This section details on the original issue you should resolve

<issue_title>Disambigaute output path for Docker Compose deployments</issue_title> <issue_description>Description When generating Docker Compose projects, the project name is derived from the directory name rather than the full subpath. This causes collisions when multiple app hosts are deployed from directories that share the same parent folder name.

For example, Aspire uses aspire-output as the output directory for multiple app hosts. Since Compose relies only on the directory name, different app hosts end up deploying into the same Docker Compose project, which results in resource conflicts.

Expected Behavior Each app host deployment should generate a distinct Compose project name, even when the output directories share a common parent folder. A unique identifier (e.g., a hash of the app host path or configuration) should be incorporated to disambiguate these project names.

Proposed Solution Include the app host's unique SHA (or similar stable identifier) in the Compose project name to prevent collisions.</issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes dotnet/aspire#12818

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Nov 07 '25 20:11 Copilot

Why is this a problem when they are child folders?

davidfowl avatar Nov 07 '25 21:11 davidfowl

Why is this a problem when they are child folders?

Child folders are only emitted for multiple Docker Compose environments within the same AppHost. This issue occurs when you have different Docker Compose environments in different AppHosts. When you don't give it an explicit project name, Docker Compses uses the base name of the directory the docker-compoase.yaml is stored in as the project name. We default this to aspire-output so it causes conflicts.

captainsafia avatar Nov 08 '25 01:11 captainsafia

Different apphosts are in different folders. I feel like I’m missing something

davidfowl avatar Nov 08 '25 05:11 davidfowl

Different apphosts are in different folders. I feel like I’m missing something

Docker only takes the immediate parent folder as the project name. Both 'A/B/aspire-output' and 'D/E/aspire-output' will have projects named aspire-output if you don't give an explicit value.

Doc: https://docs.docker.com/compose/how-tos/project-name/

captainsafia avatar Nov 08 '25 06:11 captainsafia

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12819

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12819"

github-actions[bot] avatar Nov 13 '25 02:11 github-actions[bot]