aspire icon indicating copy to clipboard operation
aspire copied to clipboard

Aspire.Host.Docker - resource published as docker-compose service, although PublishAsDockerComposeService not applied.

Open grendizeras opened this issue 2 months ago • 2 comments

Having code:

var builder = DistributedApplication.CreateBuilder(args);
 var kafkaConnectionString = builder.AddConnectionString("kafka");
 var compose = builder.AddDockerComposeEnvironment("compose")
 var redis = builder.AddRedis("redis", 6379)
 var testOrleans= builder.AddOrleans("test-orleans")
.WithClustering(redis)
.WithClusterId("test1")
.WithServiceId("test1");

var silo = builder.AddProject<Projects.Test>("test")
    .WithReference(testOrleans)
    .WithReference(redis)
    .WithReference(kafkaConnectionString)
    .WithReplicas(2)
    .WaitFor(redis)
    .PublishAsDockerComposeService((conf, service) =>
    {
        service.Name = "test";
    })

gives ouput:

services:
  compose-dashboard:
    image: "mcr.microsoft.com/dotnet/nightly/aspire-dashboard:latest"
    expose:
      - "18888"
      - "18889"
    networks:
      - "aspoire"
    restart: "always"
  redis:
    image: "docker.io/library/redis:8.2"
    command:
      - "-c"
      - "redis-server --requirepass $$REDIS_PASSWORD"
    entrypoint:
      - "/bin/sh"
    environment:
      REDIS_PASSWORD: "${REDIS_PASSWORD}"
    expose:
      - "6379"
    networks:
      - "aspire"
  test:
    image: "${TEST_IMAGE}"
...

Expected Behavior

redis should be registered as environment variable, and not as a service, otherwise what is the point of calling PublishAsDockerComposeService.

In case if redis is shipped as standalone service in production environment, it should not be published as service in docker-compose. But should work only on local aspire run/debug. If someone wants to ship redis as part of docker-compose, he should apply PublishAsDockerComposeService method on redis resource.

.NET Version info

10.0.100

aspire 13.0

grendizeras avatar Nov 12 '25 12:11 grendizeras

There's a misunderstanding. PublishAsDockerComposeService is to modify the compose service definition. By default all containers will become docker compose services. If you want to use an external redis at publish time then you'd write code like this:

 var redis = builder.ExecutionContext.IsPublishMode : builder.AddConnectionString("redis") : builder.AddRedis("redis", 6379);

davidfowl avatar Nov 16 '25 08:11 davidfowl

There's a misunderstanding. PublishAsDockerComposeService is to modify the compose service definition. By default all containers will become docker compose services. If you want to use an external redis at publish time then you'd write code like this:

var redis = builder.ExecutionContext.IsPublishMode : builder.AddConnectionString("redis") : builder.AddRedis("redis", 6379);

thanks for clarifying! but problem arises when using redis as MS Orleans' cluster management storage, because of how it is implemented in Aspire.Hosting.Orleans package. It reads type of source being used to detect storage type. in case of connection string it won't work. At least I don't know a way yo make it work. Potentially inconsistent behaviour on behalf of Orleans package?

grendizeras avatar Nov 16 '25 08:11 grendizeras

cc @ReubenBond

davidfowl avatar Nov 22 '25 07:11 davidfowl