Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

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

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

Already on GitHub? Sign in to your account

How to keep a persistent volume with AddSqlServerContainer? #974

Closed
julioct opened this issue Nov 21, 2023 · 2 comments
Closed

How to keep a persistent volume with AddSqlServerContainer? #974

julioct opened this issue Nov 21, 2023 · 2 comments
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Comments

@julioct
Copy link
Contributor

julioct commented Nov 21, 2023

I am able to use AddSqlContainer successfully in my AppHost project. The problem is that every time I stop AppHost, the container is destroyed (which is fine) but also all the data I had in the DB is destroyed with it.

I'd like to have a way to specify a persistent volume that should survive beyond the lifetime of the AppHost and get reconnected on subsequent runs.

For reference, this is my current setup:

var builder = DistributedApplication.CreateBuilder(args);

var pass = builder.Configuration["SqlPassword"];
var sql = builder.AddSqlServerContainer("sql", pass, 1433)
                 .AddDatabase("GameStore");

var backend = builder.AddProject<Projects.GameStore_Api>("backend")
                     .WithReference(sql);

builder.AddProject<Projects.GameStore_Frontend>("frontend")
       .WithReference(backend);

var app = builder.Build();

app.Run();

And this is how I run my SQL Server container manually today:

docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=$sa_password" -p 1433:1433 -v sqlvolume:/var/opt/mssql -d --rm --name mssql mcr.microsoft.com/mssql/server:2022-latest

Also, I already tried using WithVolumeMount() but it makes no difference, the data is gone.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Nov 21, 2023
@DamianEdwards
Copy link
Member

Related #923 #972

@recepgunes1
Copy link

I had similar issue with you. When I change VolumeMountType from Bind to Named, it solved. I think this is going to solve your problem. At least it worked for elasticsearch.

Also, default VolumeMountType is Bind.

        builder.AddSqlServerContainer("sql", "Passw123.", 1433)
            .AddDatabase("GameStore")
            .WithVolumeMount("sqlvolume", "/var/opt/mssql", VolumeMountType.Named);

@dotnet dotnet locked and limited conversation to collaborators Nov 29, 2023
@danmoseley danmoseley converted this issue into discussion #1109 Nov 29, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

No branches or pull requests

4 participants