Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented May 26, 2025

Changes

This PR addresses the need to mount /var/run/docker.sock into containers, enabling Docker-in-Docker scenarios. Two main changes were made:

  1. Modified the WithBindMount method to special-case Linux-style absolute paths (those starting with /):

    • Paths starting with / are now passed through directly without attempting to resolve them relative to the AppHost directory
    • This fixes issues when running on Windows with Docker socket paths
  2. Added a new convenience extension method WithDockerSocketBindMount() that:

    • Makes it simple to mount the Docker socket with a single method call
    • Automatically binds /var/run/docker.sock to /var/run/docker.sock in the container

Tests Added

  • Added a basic unit test for ContainerMountAnnotation that verifies it accepts /var/run/docker.sock as a valid bind mount source
  • Added a unit test for WithBindMount that verifies it correctly handles Docker socket paths
  • Added a unit test for the new WithDockerSocketBindMount method to verify it creates the correct annotation
  • Added a basic functional test in DockerSocketBindMountTests.cs to verify the Docker socket binding works correctly

Before this change, users could not easily mount the Docker socket into containers when specifying Linux paths on Windows hosts, as the code would incorrectly try to resolve /var/run/docker.sock as a relative path.

Fixes #7077.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 0t3vsblobprodcus362.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • 7devsblobprodcus323.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • 7k6vsblobprodcus337.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • cdn.fwupd.org
  • dlbvsblobprodcus316.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • h6tvsblobprodcus346.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • i1qvsblobprodcus353.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • imzvsblobprodcus368.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • jd4vsblobprodcus366.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • kh4vsblobprodcus325.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • ofvvsblobprodcus315.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • p2ovsblobprodcus312.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • pe4vsblobprodcus351.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • x3yvsblobprodcus370.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 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.

@github-actions github-actions bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label May 26, 2025
@Copilot Copilot AI changed the title [WIP] Allow mounting the docker socket using WithBindMount Allow mounting the docker socket using WithBindMount May 26, 2025
@Copilot Copilot AI requested a review from davidfowl May 26, 2025 10:02
Copilot finished work on behalf of davidfowl May 26, 2025 10:02
Copy link
Contributor Author

Copilot AI commented May 26, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 0t3vsblobprodcus362.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • 7devsblobprodcus323.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • 7k6vsblobprodcus337.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • dlbvsblobprodcus316.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • h6tvsblobprodcus346.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • i1qvsblobprodcus353.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • imzvsblobprodcus368.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • jd4vsblobprodcus366.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)
  • kh4vsblobprodcus325.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • ofvvsblobprodcus315.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • p2ovsblobprodcus312.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • pe4vsblobprodcus351.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)
  • x3yvsblobprodcus370.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of davidfowl May 26, 2025 10:42
Copilot finished work on behalf of davidfowl May 27, 2025 00:31
Copy link
Contributor Author

Copilot AI commented May 27, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.fwupd.org
    • Triggering command: /usr/bin/fwupdmgr refresh (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of davidfowl May 27, 2025 00:41
@davidfowl davidfowl marked this pull request as ready for review May 27, 2025 08:29

var annotation = new ContainerMountAnnotation(Path.GetFullPath(source, builder.ApplicationBuilder.AppHostDirectory), target, ContainerMountType.BindMount, isReadOnly);
// If the source starts with '/', it's a Linux-style rooted path, so we use it directly without resolution
var sourcePath = source.StartsWith('/') ? source : Path.GetFullPath(source, builder.ApplicationBuilder.AppHostDirectory);
Copy link
Member

Choose a reason for hiding this comment

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

Instead of "starts with /", should this check if the path is already rooted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to use Path.IsPathRooted() instead of checking StartsWith('/'). This is more robust as it properly handles absolute paths on different operating systems. The change was implemented in 3ed3296.

Copy link
Contributor Author

Copilot AI commented May 27, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 0t3vsblobprodcus362.vsblob.vsassets.io
    • Triggering command: ./.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj --filter FullyQualifiedName~ContainerResourceTests.WithBindMountHandlesDockerSocketPath (dns block)
  • 7devsblobprodcus323.vsblob.vsassets.io
    • Triggering command: ./.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj --filter FullyQualifiedName~ContainerResourceTests.WithBindMountHandlesDockerSocketPath (dns block)
  • 7k6vsblobprodcus337.vsblob.vsassets.io
    • Triggering command: ./.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj --filter FullyQualifiedName~ContainerResourceTests.WithBindMountHandlesDockerSocketPath (dns block)
  • dlbvsblobprodcus316.vsblob.vsassets.io
    • Triggering command: ./.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj --filter FullyQualifiedName~ContainerResourceTests.WithBindMountHandlesDockerSocketPath (dns block)
  • h6tvsblobprodcus346.vsblob.vsassets.io
    • Triggering command: ./.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj --filter FullyQualifiedName~ContainerResourceTests.WithBindMountHandlesDockerSocketPath (dns block)
  • i1qvsblobprodcus353.vsblob.vsassets.io
    • Triggering command: ./.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj --filter FullyQualifiedName~ContainerResourceTests.WithBindMountHandlesDockerSocketPath (dns block)
  • imzvsblobprodcus368.vsblob.vsassets.io
    • Triggering command: ./.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj --filter FullyQualifiedName~ContainerResourceTests.WithBindMountHandlesDockerSocketPath (dns block)
  • jd4vsblobprodcus366.vsblob.vsassets.io
    • Triggering command: ./.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj --filter FullyQualifiedName~ContainerResourceTests.WithBindMountHandlesDockerSocketPath (dns block)
  • kh4vsblobprodcus325.vsblob.vsassets.io
    • Triggering command: ./.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj --filter FullyQualifiedName~ContainerResourceTests.WithBindMountHandlesDockerSocketPath (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: ./.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj --filter FullyQualifiedName~ContainerResourceTests.WithBindMountHandlesDockerSocketPath (dns block)
  • ofvvsblobprodcus315.vsblob.vsassets.io
    • Triggering command: ./.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj --filter FullyQualifiedName~ContainerResourceTests.WithBindMountHandlesDockerSocketPath (dns block)
  • p2ovsblobprodcus312.vsblob.vsassets.io
    • Triggering command: ./.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj --filter FullyQualifiedName~ContainerResourceTests.WithBindMountHandlesDockerSocketPath (dns block)
  • pe4vsblobprodcus351.vsblob.vsassets.io
    • Triggering command: ./.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj --filter FullyQualifiedName~ContainerResourceTests.WithBindMountHandlesDockerSocketPath (dns block)
  • x3yvsblobprodcus370.vsblob.vsassets.io
    • Triggering command: ./.dotnet/dotnet test tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj --filter FullyQualifiedName~ContainerResourceTests.WithBindMountHandlesDockerSocketPath (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of eerhardt May 27, 2025 16:03
Copilot finished work on behalf of danegsta May 27, 2025 16:14
@davidfowl davidfowl merged commit 6c26138 into main May 27, 2025
500 of 502 checks passed
@davidfowl davidfowl deleted the copilot/fix-7077 branch May 27, 2025 22:52
@github-actions github-actions bot locked and limited conversation to collaborators Jun 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow mounting the docker socket using WithBindMount
7 participants