microsoft / microsoft/aspire

Persistent mongodb container recreated on every run

Open
#11,238 1 comment 1 reaction 0 assignees View on GitHub
area-integrations mongodb
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

Currently, the MongoDB container is being recreated every time it is stopped, even though the same configuration is used each time.

Image

### Expected Behavior

Only one persistent container created for any number of runs with the same configuration.

### Steps To Reproduce

var mongo = builder.AddMongoDB("mongo", 27020)
.WithContainerName("mongo")
.WithEnvironment("MONGO_INITDB_DATABASE", "MyTestDB")
.WithEnvironment("MONGO_INITDB_ROOT_USERNAME", "user")
.WithEnvironment("MONGO_INITDB_ROOT_PASSWORD", "pass")
.WithDataVolume("mtmongodata")
.WithBindMount("./init-mongo.js", "/docker-entrypoint-initdb.d/mongo-init.js", isReadOnly: true)
.WithLifetime(ContainerLifetime.Persistent);

1. Run the aspire project with this configuration
2. After the projected started successfully, run `docker stop `
3. Run again the aspire project with the same configuration.

### Exceptions (if any)

_No response_

### .NET Version info

.NET SDK:
Version: 9.0.304
Commit: f12f5f689e
Workload version: 9.0.300-manifests.610a1858
MSBuild version: 17.14.16+5d8159c5f

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.304\

### Anything else?

Project target framework: NET 9.0
Aspire.Hosting.AppHost version: 9.3.1
Aspire.Hosting.MongoDB version: 9.3.1

Contributor guide

Open the contributing guide

Research direction

Start by tracing the container handling behind WithLifetime(ContainerLifetime.Persistent) and the provided MongoDB configuration, then reproduce the stop-and-rerun sequence. Done means rerunning the same Aspire project reuses the existing stopped container instead of creating another one.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, docker, mongodb
Domain
infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.