Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Sql Server container port is not accessible after Aspire is shutdown #7046

Open
1 task done
christophe-mommer opened this issue Jan 8, 2025 · 7 comments
Open
1 task done
Milestone

Comments

@christophe-mommer
Copy link

christophe-mommer commented Jan 8, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I'm using Aspire to orchestrate my webapp and my database. I'm also using this database as part of several other projects, like test project.
Here's my setup:

var password = builder.AddParameter("sqlpassword", secret: true);
var sqlServer = builder
    .AddSqlServer(ConfigurationConstants.SqlServerConnectionName, password, 1433)
    .WithLifetime(ContainerLifetime.Persistent)
    .WithDataVolume(name: ConfigurationConstants.SqlServerDataVolumeName, isReadOnly: false)
    .WithContainerName("sql-server");

var sqlDatabase = sqlServer.AddDatabase(ConfigurationConstants.SqlDatabaseConnectionName);

webFrontEnd
    .WithReference(sqlDatabase)
    .WaitFor(sqlDatabase);

The thing is: when my Aspire app si running, I can access the database on port 1433 from other applications, even SSMS. However, when I shutdown my Aspire project, this database is no more accessible, even though it's marked as persistent. The container is still there, but the random port is the only one that allows me to acces the database, not the 1433 that I've specified.

Have I missed something in my configuration?

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version info

.NET 9, Aspire 9

Anything else?

No response

@davidfowl davidfowl added area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication area-orchestrator labels Jan 8, 2025
@maddymontaquila
Copy link
Member

cc @danegsta

@maddymontaquila maddymontaquila added this to the 9.1 milestone Jan 10, 2025
@maddymontaquila
Copy link
Member

@lupusbytes quick fyi - when using ContainerLifetime.Persistent it does stay running when Aspire shuts down - you can tell because in Docker Desktop it still shows it as "running", so yeah this is a bug 😁

@karolz-ms
Copy link
Member

My guess here is that AddSqlServer() () is using proxied endpoint for a persistent container, and once the app host stops, the proxy is gone, and the port specified is no longer valid. As a rule, it probably does not make sense to use proxied endpoints for persistent containers.

So If that is correct, it is not a feature, but just a bug in the app model.

@karolz-ms
Copy link
Member

Actually, the feature that we might be missing is "change the type of the endpoint depending on whether the container is persistent"

@garrettlondon1
Copy link

garrettlondon1 commented Jan 17, 2025

Can confirm as well, not able to connect to local sql server database running in docker container via Azure Data Studio without aspire running.

@davidfowl
Copy link
Member

Actually, the feature that we might be missing is "change the type of the endpoint depending on whether the container is persistent"

We should just do this automatically right?

@karolz-ms
Copy link
Member

Actually, the feature that we might be missing is "change the type of the endpoint depending on whether the container is persistent"

We should just do this automatically right?

@danegsta is working on making non-proxied endpoints the default for persistent containers.

@davidfowl davidfowl removed the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Jan 21, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

5 participants