microsoft / microsoft/aspire

RabbitMQ container could not start because of multip calling of WithEndpoint method.

Open
#12,751 1 comment 0 reactions 0 assignees View on GitHub
needs-area-label
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

I add a rabbitmq container and use WithEndpoint method twice to expose two endpoints, but AppHost could not start the container, the error log I have paste in exceptions part, here is my code:
```
var rabbitmqUserName = builder.AddParameter("rabbitmq-username", "admin");
var rabbitmqPassword = builder.AddParameter("rabbitmq-password", "admin123");
var upstreamRabbitmq = builder.AddRabbitMQ("upstream-rabbitmq", rabbitmqUserName, rabbitmqPassword)
.WithImage("rabbitmq:management")
.WithContainerName("upstreamRabbitmq")
.WithLifetime(ContainerLifetime.Persistent)
.WithExternalHttpEndpoints()
.WithEnvironment("TZ", "Asia/Shanghai")
.WithEnvironment("RABBITMQ_DEFAULT_USER", rabbitmqUserName)
.WithEnvironment("RABBITMQ_DEFAULT_PASS", rabbitmqPassword)
.WithEnvironment("RABBITMQ_LOOPBACK_USERS", "[]")
.WithEndpoint("rabbit-management", endpoint =>
{
endpoint.Port = 24000;
endpoint.TargetPort = 15672;
})
.WithEndpoint("rabbit-mq", endpoint =>
{
endpoint.Port = 24100;
endpoint.TargetPort = 5672;
});
```
If i remove the last WithEndpoint, the container could start successfully.

### Expected Behavior

The rabbitMQ container could start successfully and exposes two ports.

### Steps To Reproduce

_No response_

### Exceptions (if any)

```
fail: Aspire.Hosting.Dcp.dcpctrl.dcpctrl.ContainerReconciler[0]
Failed to start Container {"Container": "/upstreamRabbitmq", "Reconciliation": 17, "ContainerID": "02c987d94d9c", "ContainerName": "upstreamRabbitmq", "error": "status of container 'upstreamRabbitmq' is 'created' (was expecting 'running'), error: failed to set up container networking: driver failed programming external connectivity on endpoint upstreamRabbitmq (d87d974a0f4e8f003b18d176d91a82a8471432e058d939379470778b32e36a73): failed to listen on TCP socket: address already in use\ndocker command 'StartContainers' returned with non-zero exit code 1\nnot all requested objects were returned\nonly 0 out of 1 containers were successfully started"}
Aspire.Hosting.Dcp.dcpctrl.dcpctrl.ContainerReconciler: Error: Failed to start Container {"Container": "/upstreamRabbitmq", "Reconciliation": 17, "ContainerID": "02c987d94d9c", "ContainerName": "upstreamRabbitmq", "error": "status of container 'upstreamRabbitmq' is 'created' (was expecting 'running'), error: failed to set up container networking: driver failed programming external connectivity on endpoint upstreamRabbitmq (d87d974a0f4e8f003b18d176d91a82a8471432e058d939379470778b32e36a73): failed to listen on TCP socket: address already in use\ndocker command 'StartContainers' returned with non-zero exit code 1\nnot all requested objects were returned\nonly 0 out of 1 containers were successfully started"}
```

### .NET Version info

.NET SDK:
Version: 9.0.103
Commit: 96da45d427
Workload version: 9.0.100-manifests.b73bf4bc
MSBuild version: 17.12.24+90b52dda6

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.103\

### Anything else?

I use VS Code as IDE.
Here is my AppHost project configuration(I have hidden UserSecretsId section).
```



Exe
net9.0
enable
enable
true
************









```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.