aspire: .WithDataBindMount() not working with EF and Postgres or MongoDB

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I’m unable to get .WithDataBindMount() working with EF and Postgres or MongoDB.

The included sample works great if I use .WithDataVolume() instead of .WithDataBindMount(). I was unable to find any online examples of how to use .WithDataBindMount() in this sort of context.

The sample repo showing this problem is a minimal fork of a repo described in a blog post by @NikiforovAll. The blog post and original repo describe what is basically a hello world Aspire database sample. The original version works great, the forked version crashes, and the only difference is .WithDataBindMount() vs .WithDataVolume().

The AppHost has for example:

var usersDb = builder
    .AddPostgres("dbserver", pAdmin, password)
    //.WithDataVolume()
    .WithDataBindMount("../../volumes/PostgresUsersDb")
    .WithPgAdmin(c => c.WithHostPort(5050))
    .AddDatabase("users-db");

When the running code attempts a migration to populate the databases, the code throws an exception in await dbCreator.ExistsAsync(cancellationToken) that is Npgsql.NpgsqlException: Exception while reading from stream in the following database migration code:

private static async Task EnsureDatabaseAsync(
    UsersDbContext context,
    CancellationToken cancellationToken
)
{
    var dbCreator = context.GetService<IRelationalDatabaseCreator>();
    var strategy = context.Database.CreateExecutionStrategy();
    await strategy.ExecuteAsync(async () =>
    {
        // Create the database if it does not exist.
        // Do this first so there is then a database to start a transaction against.
        if (!await dbCreator.ExistsAsync(cancellationToken))
        {
            await dbCreator.CreateAsync(cancellationToken);
        }
    });
}

The AppHost throws a similar exception in an .AddMongoDB() context but successfully executes in an .AddElasticsearch() context.

Again, for clarity, the sample code runs without issue if configured to use .WithDataVolume(), the issue only happens with .WithDataBindMount().

Expected Behavior

The Aspire project should successfully initialize the Postgres and MongoDB databases when launched.

Steps To Reproduce

Exceptions (if any)

When the running code attempts a migration to populate the databases, the code throws an exception in await dbCreator.ExistsAsync(cancellationToken) that is Npgsql.NpgsqlException: Exception while reading from stream

.NET Version info

.NET SDK: Version: 8.0.201 Commit: 4c2d78f037 Workload version: 8.0.200-manifests.011fccd5

Runtime Environment: OS Name: Mac OS X OS Version: 14.5 OS Platform: Darwin RID: osx-arm64 Base Path: /usr/local/share/dotnet/sdk/8.0.201/

.NET workloads installed: [aspire] Installation Source: SDK 8.0.200 Manifest Version: 8.0.1/8.0.100 Manifest Path: /usr/local/share/dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.aspire/8.0.1/WorkloadManifest.json Install Type: FileBased

Host: Version: 8.0.4 Architecture: arm64 Commit: 2d7eea2529

.NET SDKs installed: 6.0.401 [/usr/local/share/dotnet/sdk] 6.0.403 [/usr/local/share/dotnet/sdk] 6.0.404 [/usr/local/share/dotnet/sdk] 6.0.405 [/usr/local/share/dotnet/sdk] 6.0.407 [/usr/local/share/dotnet/sdk] 6.0.408 [/usr/local/share/dotnet/sdk] 6.0.410 [/usr/local/share/dotnet/sdk] 6.0.413 [/usr/local/share/dotnet/sdk] 6.0.415 [/usr/local/share/dotnet/sdk] 7.0.100 [/usr/local/share/dotnet/sdk] 7.0.101 [/usr/local/share/dotnet/sdk] 7.0.102 [/usr/local/share/dotnet/sdk] 7.0.202 [/usr/local/share/dotnet/sdk] 7.0.203 [/usr/local/share/dotnet/sdk] 7.0.304 [/usr/local/share/dotnet/sdk] 7.0.307 [/usr/local/share/dotnet/sdk] 8.0.100 [/usr/local/share/dotnet/sdk] 8.0.201 [/usr/local/share/dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.15 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.16 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.18 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.21 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.23 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.15 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.16 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.18 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.21 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.23 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found: x64 [/usr/local/share/dotnet/x64]

Environment variables: Not set

global.json file: Not found

Anything else?

I’m using Rider on apple silicon, presumably Visual Studio will exhibit the same issues

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 21 (12 by maintainers)

Most upvoted comments

Could the docs please be updated to say which are and are not supported, so this issue isn’t the definitive source of that info?


From: David Fowler @.> Sent: Monday, November 4, 2024 12:19:23 AM To: dotnet/aspire @.> Cc: Don Alvarez @.>; Mention @.> Subject: Re: [dotnet/aspire] .WithDataBindMount() not working with EF and Postgres or MongoDB (Issue #4956)

Rancher is currently unsupported, can you use podman desktop instead?

— Reply to this email directly, view it on GitHubhttps://github.com/dotnet/aspire/issues/4956#issuecomment-2453846750, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AANN3QMHESBE46SOKU43R2LZ63YUXAVCNFSM6AAAAABLB4QUBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINJTHA2DMNZVGA. You are receiving this because you were mentioned.Message ID: @.***>

@DamianEdwards I’m not able to test with Docker on OSX, but I did include a minimal repo in the initial report that provides a full repro for the issue.

Also, I wasn’t expressing frustration I was trying to indicate the reverse: I’ve personally worked around this issue and what’s important is the developer experience for new developers. My point was given the importance of databases in Aspire projects, this issue should be prioritized in the push to get v9 out.

@DamianEdwards DCP explicitly creates folders for a bind mount share if one isn’t present. We do this to make the behavior consistent between Docker and Podman. Docker, by default, would create a folder for a bind mount if the specified path doesn’t exist, but it would also always create the folder as root. On the other hand, Podman out of the box won’t create a missing bind mount path at all and will just report an error. We split the difference and create the missing folder as the current user before starting the container.

@DamianEdwards running the sample with empty directories doesn’t fix the problem. It removes the error about unable to chown .gitkeep but doesn’t remove the error about unable to chown the data related directory.