Skip to content

With* methods don't work with containers #128

@davidfowl

Description

@davidfowl

I was testing a project converter to container locally and I realized that it doesn't work because we pass the localhost address instead of using the host address (host.docker.internal). Localhost is local to this container so this always blows up.

using Aspire.Hosting.Otlp;
using Aspire.Hosting.Redis;

var builder = DistributedApplication.CreateBuilder(args);

var pubsub = builder.AddRedisContainer("pubsub");

// Projects
//builder.AddProject<RedisPubSub.App.Projects.Publisher>()
//    .WithRedis(pubsub);

//builder.AddProject<RedisPubSub.App.Projects.Subscriber>()
//    .WithRedis(pubsub);

// Project published as containers
builder.AddContainer("publisher", "publisher")
    .WithRedis(pubsub)
    .WithOtlpExporter();

builder.AddContainer("subscriber", "subscriber")
    .WithRedis(pubsub)
    .WithOtlpExporter();

builder.Build().Run();

The easiest fix here would be to always use host.docker.internal instead of localhost for anything that runs in a container. Injecting different environment based on the consumer might be a bit more difficult...

cc @karolz-ms

Metadata

Metadata

Assignees

Labels

area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplicationarea-orchestrator

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions