testcontainers / testcontainers/testcontainers-java

MongoDBContainer doesn't start DB in --auth mode

Open
#4,200 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
8.7k
Forks
1.9k
Avg merge
2d 17h
Merged PRs (30d)
9

Description

val mongoContainer = 
 new MongoDBContainer(DockerImageName.parse("mongo:4.0.10")
      .asCompatibleSubstituteFor("mongo"))
      .withCommand("--auth", "--replSet", "docker-rs")
      .withEnv("MONGO_INITDB_DATABASE", "admin")
      .withEnv("MONGO_INITDB_ROOT_USERNAME", "admin")
      .withEnv("MONGO_INITDB_ROOT_PASSWORD", "whatever")

mongoContainer.start()
2021-06-15 11:51:08,270 [ForkJoinPool-1-worker-29] INFO  org.testcontainers.DockerClientFactory - Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
2021-06-15 11:51:08,270 [ForkJoinPool-1-worker-29] INFO  org.testcontainers.DockerClientFactory - Checking the system...
2021-06-15 11:51:08,270 [ForkJoinPool-1-worker-29] INFO  org.testcontainers.DockerClientFactory - ✔︎ Docker server version should be at least 1.6.0
2021-06-15 11:51:08,343 [ForkJoinPool-1-worker-29] INFO  org.testcontainers.DockerClientFactory - ✔︎ Docker environment should have more than 2GB free disk space
2021-06-15 11:51:46,218 [ForkJoinPool-1-worker-29] ERROR org.testcontainers.containers.MongoDBContainer - An error occurred: MongoDB shell version v4.0.10
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2021-06-15T09:51:46.219+0000 E QUERY    [js] Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27017'  :
connect@src/mongo/shell/mongo.js:344:17
@(connect):2:6

2021-06-15 11:51:46,219 [ForkJoinPool-1-worker-29] ERROR 🐳 [mongo:4.0.10] - Could not start container
org.testcontainers.containers.MongoDBContainer$ReplicaSetInitializationException: An error occurred: MongoDB shell version v4.0.10
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2021-06-15T09:51:46.219+0000 E QUERY    [js] Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27017'  :
connect@src/mongo/shell/mongo.js:344:17
@(connect):2:6

what is the right way to make it work? Can I patch the container somehow?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with MongoDBContainer and its replica-set initialization, reproducing the failure using the --auth configuration and mongo:4.0.10 shown here. Trace why the initialization command cannot connect, then verify that the container starts successfully with authentication and replica-set options enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, java, mongodb, scala
Domain
databases, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.