-
-
Notifications
You must be signed in to change notification settings - Fork 250
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
MongoDb Replica Set Mode Exits #538
Comments
It looks like that the container does not start properly (it exits almost immediately). With the example above, I get the following error: [...]
BadValue: security.keyFile is required when authorization is enabled with replica sets
try 'mongod --help' for more information
[...]
MongoDB init process complete; ready for start up. If I create the security key file, set the right permissions and assign the public sealed class GitHub : IAsyncLifetime
{
private static readonly string Source = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
private static readonly string Destination = "/docker-entrypoint-initdb.d";
private static readonly string SecurityKeyFilePath = $"{Destination}/replica.key";
private readonly TestcontainerDatabase mongoDb = new TestcontainersBuilder<MongoDbTestcontainer>()
.WithDatabase(new MongoDbTestcontainerConfiguration { Database = "GitHub", Username = "mongodb", Password = "mongodb" })
.WithBindMount(Source, Destination)
.WithEntrypoint("/bin/sh", "-c", $"chown 999:999 {SecurityKeyFilePath} && mongod")
.WithCommand("--replSet", "repro")
.Build();
[Fact]
public Task Issue538()
{
return Task.CompletedTask;
}
public Task InitializeAsync()
{
return this.mongoDb.StartAsync();
}
public Task DisposeAsync()
{
return this.mongoDb.DisposeAsync().AsTask();
}
} Is your security key file setup properly? |
Interesting, I didn't even know about that setting / haven't had to configure it up to this point using docker compose - I will take a look, thank you 😀 |
I tried fiddling with the security key but that was painful.. Instead I just removed the username/password, because the security key is not required if auth isn't set up. The only issue is that the connection string has the auth component even though there's no username/password
Instead of
Easy enough to fix in my code with a string replacement, though I wonder if the package should just not include this component of the connection string if Either way, thank you for the help! :) |
OC, we can change the behavior. Modules heavily rely on contribution, I'm not a MongoDB expert. Supporting more use cases would be great. If you have any improvement in mind, a contribution is more than welcome. |
Describe the bug
It appears that the MongoDb container cannot be switched to replica set mode - the container just exits after completing initialization. When I run an equivalent setup using
docker-compose.yml
(albeit not using resource reaper), I do not have the issue - the container keeps running just fine and replica set mode is available for usage.To Reproduce
Make an xunit test.
Add the following file, with paths relative to the test project's csproj file, and configure the csproj to always copy this file to output.
./DockerEntrypoints/MongoDb/Init/init.js
Create this fixture and inject it into a test.
The following error (or similar) is thrown in InitializeAsync:
The task exists, and if you look into the logs, the last line will be:
Expected behavior
If you run an equivalent setup using docker-compose, the container does not exit - it keeps going.
Desktop (please complete the following information):
4.3.2 / v20.10.11 (Docker Version?)
Additional context
Replica set mode allows for MongoDb transactions. It's very critical to have transactions in my tests.
The text was updated successfully, but these errors were encountered: