Open Chris-Sheridan opened 1 month ago
I faced same issue and I would like to work on this bug.
To replicate the issue i added below test case for mongo:6
.
{
name: "With Replica set, WithUsername, WithPassword and mongo:6",
img: "mongo:6",
opts: []testcontainers.ContainerCustomizer{
mongodb.WithReplicaSet("rs"),
mongodb.WithUsername("tester"),
mongodb.WithPassword("testpass"),
},
}
The test failed with below error.
=== RUN TestMongoDB
=== RUN TestMongoDB/With_Replica_set,_WithUsername,_WithPassword_and_mongo:6
=== PAUSE TestMongoDB/With_Replica_set,_WithUsername,_WithPassword_and_mongo:6
=== CONT TestMongoDB/With_Replica_set,_WithUsername,_WithPassword_and_mongo:6
mongodb_test.go:80:
Error Trace: ~/testcontainers-go/modules/mongodb/mongodb_test.go:80
Error: Received unexpected error:
generic container: start container: started hook: container exec create: Error response from daemon: Container 37d341411e5c383c4718f8108f99ea63265418208ffe887db14fc881bb55d4c3 is not running
all exposed ports, [27017/tcp], were not mapped in 5s: port 27017/tcp is not mapped yet
wait until ready: check target: retries: 1, port: "", last err: container exited with code 2
Test: TestMongoDB/With_Replica_set,_WithUsername,_WithPassword_and_mongo:6
--- FAIL: TestMongoDB/With_Replica_set,_WithUsername,_WithPassword_and_mongo:6 (89.00s)
It seems when root username and password are set in mongodb containers then security.keyfile must be passed. On debugging and checking the logs of testcontainer i found below error in logs.
Container logs for container: 785fef5b21876ed71a15c1be0a54363bf0bc3b1ccc96ba01f797606ccdd85cac
about to fork child process, waiting until server is ready for connections.
forked process: 28
}
MongoDB init process complete; ready for start up.
<some other logs: redacted>
BadValue: security.keyFile is required when authorization is enabled with replica sets
try 'mongod --help' for more information
Adding keyfile inside container is not very straight forward. The keyfile requires specific permission and should be read only by mongodb user or group members.
Adding file is not a problem as we can use add it through Files
in container request. But adding it with proper ownership is not easy.
@mdelapenya Can you suggest if there is a way to add file to containers with specific ownership. Also it is worth solving this problem. I think another approach is to allow replicaset without username passwords.
Testcontainers version
v0.33.0
Using the latest Testcontainers version?
Yes
Host OS
MacOS
Host arch
ARM
Go version
1.23.0
Docker version
Docker info
What happened?
When running the following code, I consistently receive the error message stated in the log output. I tried different mongo versions and with/without wait strategies and it's the same result.
mongo, err := mongodb.Run(ctx, "mongo:latest", mongodb.WithReplicaSet("rs0"), mongodb.WithUsername("root"), mongodb.WithPassword("example"), testcontainers.WithWaitStrategy(wait.ForLog("Waiting for connections")), )
Relevant log output
Additional information
No response