StackExchange/StackExchange.Redis

Error: No endpoints specified (Parameter 'config'), when connecting from Docker container

uwDavid opened this issue · 5 comments

My .NET 8 application works when running locally.
However, when I containerize my application using dotnet publish, I would get this error:
No endpoints specified (Parameter 'config')

Pretty sure the connection string for Docker container is set up correctly using Environment Override.

Appreciate any help.

fail: Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService[103]
      Health check redis with status Unhealthy completed after 4.7841ms with message '(null)'
      System.ArgumentException: No endpoints specified (Parameter 'config')
         at StackExchange.Redis.ConnectionMultiplexer.Validate(ConfigurationOptions config) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 653
         at StackExchange.Redis.ConnectionMultiplexer.ConnectAsync(ConfigurationOptions configuration, TextWriter log) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 595
         at StackExchange.Redis.ConnectionMultiplexer.ConnectAsync(String configuration, TextWriter log) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 575
         at HealthChecks.Redis.RedisHealthCheck.CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken) in /_/src/HealthChecks.Redis/RedisHealthCheck.cs:line 53
fail: Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService[103]
      Health check redis with status Unhealthy completed after 0.1376ms with message '(null)'
      System.ArgumentException: No endpoints specified (Parameter 'config')
         at StackExchange.Redis.ConnectionMultiplexer.Validate(ConfigurationOptions config) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 653
         at StackExchange.Redis.ConnectionMultiplexer.ConnectAsync(ConfigurationOptions configuration, TextWriter log) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 595
         at StackExchange.Redis.ConnectionMultiplexer.ConnectAsync(String configuration, TextWriter log) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 575
         at HealthChecks.Redis.RedisHealthCheck.CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken) in /_/src/HealthChecks.Redis/RedisHealthCheck.cs:line 53

My Program.cs

builder.Services.AddStackExchangeRedisCache(options =>
{
    options.Configuration = builder.Configuration.GetConnectionString("Redis");
});

appsettings.json

"ConnectionStrings": {
    "Redis": "localhost:6379"
  }

docker-compose.yml

basket-api:
    container_name: basket-api
    image: basket-api
    environment:
      - ConnectionStrings__Redis=cache:6379;
    ports:
      - "6001:8080"
    depends_on:
      - cache
    links:
      - cache

cache:
    image: redis
    container_name: cache
    restart: always
    ports:
      - "6379:6379"

If you write out the value of builder.Configuration.GetConnectionString("Redis"), what does that evaluate to in the failing deployment?

If you write out the value of builder.Configuration.GetConnectionString("Redis"), what does that evaluate to in the failing deployment?

Thanks for looking.

It's taking the value "cache:6379" as expected.

I have also tried using "host.docker.internal:6379"

I don't think we respect the empty option resulting in an invalid parse there - please try to adjust your YAML without the semicolon:

environment:
      - ConnectionStrings__Redis=cache:6379

I don't think we respect the empty option resulting in an invalid parse there - please try to adjust your YAML without the semicolon:

environment:
      - ConnectionStrings__Redis=cache:6379

Thank you! Let me try it and report back.

I don't think we respect the empty option resulting in an invalid parse there - please try to adjust your YAML without the semicolon:

environment:
      - ConnectionStrings__Redis=cache:6379

Happy to report back that this is working!

Going to investigate your comment on the parsing to learn a little more.

Thank you both!