aspire: could not connect a container to the network

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

This issue occurs when I do dotnet run in the AppHost project, It does not affect the running of the applications however this error is repeated and is printed every second for all the containers

fail: Aspire.Hosting.Dcp.dcpctrl.NetworkReconciler[0]
      could not connect a container to the network      {"NetworkName": {"name":"default-aspire-network"}, "Reconciliation": 11, "Container": "452393e9a799e8624d921d36b88fa2e187a220d89cc3f5c528b8a59b617a7b7f", "Network": "default-aspire-network-4vd3gfu7i8", "error": "podman command 'ConnectNetwork' returned with non-zero exit code 125: command output: Stdout: '' Stderr: 'Error: container 452393e9a799e8624d921d36b88fa2e187a220d89cc3f5c528b8a59b617a7b7f is already connected to network default-aspire-network-4vd3gfu7i8: network is already connected\n'"}
fail: Aspire.Hosting.Dcp.dcpctrl.NetworkReconciler[0]
      could not connect a container to the network      {"NetworkName": {"name":"default-aspire-network"}, "Reconciliation": 11, "Container": "0c3bd72d02478e9e67e976fca7a8a11eca7dc5bbb493319dc689dda022c2ff5a", "Network": "default-aspire-network-4vd3gfu7i8", "error": "podman command 'ConnectNetwork' returned with non-zero exit code 125: command output: Stdout: '' Stderr: 'Error: container 0c3bd72d02478e9e67e976fca7a8a11eca7dc5bbb493319dc689dda022c2ff5a is already connected to network default-aspire-network-4vd3gfu7i8: network is already connected\n'"}
fail: Aspire.Hosting.Dcp.dcpctrl.NetworkReconciler[0]
      could not connect a container to the network      {"NetworkName": {"name":"default-aspire-network"}, "Reconciliation": 11, "Container": "40933e042ba65600e082a0a5299a02500a136fdc9be916f987871669d4ce6909", "Network": "default-aspire-network-4vd3gfu7i8", "error": "podman command 'ConnectNetwork' returned with non-zero exit code 125: command output: Stdout: '' Stderr: 'Error: container 40933e042ba65600e082a0a5299a02500a136fdc9be916f987871669d4ce6909 is already connected to network default-aspire-network-4vd3gfu7i8: network is already connected\n'"}
fail: Aspire.Hosting.Dcp.dcpctrl.NetworkReconciler[0]
      could not connect a container to the network      {"NetworkName": {"name":"default-aspire-network"}, "Reconciliation": 12, "Container": "452393e9a799e8624d921d36b88fa2e187a220d89cc3f5c528b8a59b617a7b7f", "Network": "default-aspire-network-4vd3gfu7i8", "error": "podman command 'ConnectNetwork' returned with non-zero exit code 125: command output: Stdout: '' Stderr: 'Error: container 452393e9a799e8624d921d36b88fa2e187a220d89cc3f5c528b8a59b617a7b7f is already connected to network default-aspire-network-4vd3gfu7i8: network is already connected\n'"}
fail: Aspire.Hosting.Dcp.dcpctrl.NetworkReconciler[0]
      could not connect a container to the network      {"NetworkName": {"name":"default-aspire-network"}, "Reconciliation": 12, "Container": "0c3bd72d02478e9e67e976fca7a8a11eca7dc5bbb493319dc689dda022c2ff5a", "Network": "default-aspire-network-4vd3gfu7i8", "error": "podman command 'ConnectNetwork' returned with non-zero exit code 125: command output: Stdout: '' Stderr: 'Error: container 0c3bd72d02478e9e67e976fca7a8a11eca7dc5bbb493319dc689dda022c2ff5a is already connected to network default-aspire-network-4vd3gfu7i8: network is already connected\n'"}
fail: Aspire.Hosting.Dcp.dcpctrl.NetworkReconciler[0]
      could not connect a container to the network      {"NetworkName": {"name":"default-aspire-network"}, "Reconciliation": 12, "Container": "40933e042ba65600e082a0a5299a02500a136fdc9be916f987871669d4ce6909", "Network": "default-aspire-network-4vd3gfu7i8", "error": "podman command 'ConnectNetwork' returned with non-zero exit code 125: command output: Stdout: '' Stderr: 'Error: container 40933e042ba65600e082a0a5299a02500a136fdc9be916f987871669d4ce6909 is already connected to network default-aspire-network-4vd3gfu7i8: network is already connected\n'"}

Here is my csproj file

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <IsAspireHost>true</IsAspireHost>
    <UserSecretsId>d0ee5701-532e-470f-ae99-a0d293698115</UserSecretsId>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Aspire.Hosting.AppHost" Version="8.2.2" />
    <PackageReference Include="Aspire.Hosting.Keycloak" Version="9.0.0-preview.4.24511.1" />
    <PackageReference Include="Aspire.Hosting.PostgreSQL" Version="8.2.2" />
  </ItemGroup>

  <ItemGroup>
 other project references here which I've omitted...
  </ItemGroup>

</Project>

I’m on linux ubuntu, podman version

> podman -v
podman version 4.9.3

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version info

dotnet --info
.NET SDK:
 Version:           9.0.100-rc.2.24474.11
 Commit:            315e1305db
 Workload version:  9.0.100-manifests.3424025a
 MSBuild version:   17.12.0-preview-24473-03+fea15fbd1

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  24.04
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /home/shrikanth/dotnet/sdk/9.0.100-rc.2.24474.11/

.NET workloads installed:
 [aspire]
   Installation Source: SDK 9.0.100-rc.2
   Manifest Version:    8.2.2/8.0.100
   Manifest Path:       /home/shrikanth/dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.aspire/8.2.2/WorkloadManifest.json
   Install Type:        FileBased

Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.0-rc.2.24473.5
  Architecture: x64
  Commit:       990ebf52fc

.NET SDKs installed:
  9.0.100-rc.2.24474.11 [/home/shrikanth/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0-rc.2.24474.3 [/home/shrikanth/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0-rc.2.24473.5 [/home/shrikanth/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/downloa

Anything else?

My Program.cs file

var builder = DistributedApplication.CreateBuilder(args);

var postgres = builder.AddPostgres("postgres")
                .WithPgWeb();
var database = postgres.AddDatabase("conductor");

var identity = builder.AddKeycloak("idp", 8443);

var automations = builder.AddProject<Projects.Conductor_Automations>("automations")
    .WithReference(database)
    .WaitFor(database);

var webapi = builder.AddProject<Projects.Conductor_WebApi>("webapi")
    .WithExternalHttpEndpoints()
    .WithReference(identity)
    .WithReference(database)
    .WaitFor(database);

builder.Build().Run();

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 24 (9 by maintainers)

Most upvoted comments

I found that this problem happens if I manually kill the Aspire Developer Control Pane (DCP) while it’s cleaning up.

Specifically, when it does not clean up the Docker networks default-aspire-network-*. I ran this command to delete all my orphaned aspire networks, after which the problem was fixed.

docker network ls --filter name=default-aspire-network- -q | xargs -r docker network rm

The next version of the .NET SDK 9.0.200, see https://github.com/dotnet/sdk/issues/36971

Should be fixed (Aspire main branch) by https://github.com/dotnet/aspire/pull/7085.

The dotnet watch issue is fixed in the next version.

@karolz-ms I’ve created one here https://github.com/tang2087/aspire-example/tree/main However i am hitting a new issue that the sql server container cannot start. I will fix it later (after work). Despite of that, the error message already shows as well:

      could not connect a container to the network      {"NetworkName": {"name":"default-aspire-network"}, "Reconciliation": 8, "Container": "834e3b95b68976d8fd4b684061869303f7038cf9e64ef278091406ca33959458", "Network": "default-aspire-network-k6l8o0auf8", "error": "container 834e3b95b68976d8fd4b684061869303f7038cf9e64ef278091406ca33959458 is not connected to network 7957dba6640ba7dbc309e0de81499db467264999493602e0972c20392044e744"}
fail: Aspire.Hosting.Dcp.dcpctrl.NetworkReconciler[0]
      could not connect a container to the network      {"NetworkName": {"name":"default-aspire-network"}, "Reconciliation": 9, "Container": "834e3b95b68976d8fd4b684061869303f7038cf9e64ef278091406ca33959458", "Network": "default-aspire-network-k6l8o0auf8", "error": "container 834e3b95b68976d8fd4b684061869303f7038cf9e64ef278091406ca33959458 is not connected to network 7957dba6640ba7dbc309e0de81499db467264999493602e0972c20392044e744"}
fail: Aspire.Hosting.Dcp.dcpctrl.NetworkReconciler[0]
      could not connect a container to the network      {"NetworkName": {"name":"default-aspire-network"}, "Reconciliation": 10, "Container": "834e3b95b68976d8fd4b684061869303f7038cf9e64ef278091406ca33959458", "Network": "default-aspire-network-k6l8o0auf8", "error": "container 834e3b95b68976d8fd4b684061869303f7038cf9e64ef278091406ca33959458 is not connected to network 7957dba6640ba7dbc309e0de81499db467264999493602e0972c20392044e744"}
fail: Aspire.Hosting.Dcp.dcpctrl.NetworkReconciler[0]
      could not connect a container to the network      {"NetworkName": {"name":"default-aspire-network"}, "Reconciliation": 11, "Container": "834e3b95b68976d8fd4b684061869303f7038cf9e64ef278091406ca33959458", "Network": "default-aspire-network-k6l8o0auf8", "error": "container 834e3b95b68976d8fd4b684061869303f7038cf9e64ef278091406ca33959458 is not connected to network 7957dba6640ba7dbc309e0de81499db467264999493602e0972c20392044e744"}

@tang2087 please double check what is the version of the Aspire.Hosting.Orchestration package that your application/test is using (e.g. do a ps aux and note where dcp and dcpctrl executables are loaded from). Then do dcp version using that path. You want to see 0.10.1 or newer, not 0.9.something. I have heard from at least one other developer that reference the newer version of the app host package but somehow ended up using the old application orchestrator (DCP).

If you are using the version 0.10.1 or newer but still see the issue, I would really appreciate sharing a way to reproduce it.

~/.nuget/packages/aspire.hosting.orchestration.linux-x64/9.1.0-preview.1.25068.4/tools$ ./dcp version
{"version":"0.10.2","commitHash":"e4668ec7e6f98197599a8ff06d5eafb0a84fb427","buildTimestamp":"2025-01-16T23:45:08Z"}

I also pruned networks.

I will try to publish a project somewhere to reproduce this.

You can use docker network prune

@joperezr I updated to Aspire 9.0.0 and that seems to fix it for me Thanks