testcontainers / testcontainers/testcontainers-java
Support init scripts for `MongoDBContainer` without manually customizing the `WaitStrategy`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
A container initialized as follows, fails to start:
MongoDBContainer c = new MongoDBContainer(MONGO_IMAGE)
.withEnv("MONGO_INITDB_ROOT_USERNAME", "root")
.withEnv("MONGO_INITDB_ROOT_PASSWORD", "password" )
.withFileSystemBind("init/mongo-init.js",
"/docker-entrypoint-initdb.d/mongo-init.js", BindMode.READ_ONLY)
;
c.start()
Not sure but probably because the docker-entrypoint.sh, in case of presence of init-db scripts, does a shutdown and a restart of the process after executing them:
if [ -n "$shouldPerformInitdb" ]; then
...
echo
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.js) echo "$0: running $f"; "${mongo[@]}" "$MONGO_INITDB_DATABASE" "$f"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
"${mongodHackedArgs[@]}" --shutdown
rm -f "$pidfile"
...
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the MongoDBContainer example with the init/mongo-init.js bind mount and compare its startup behavior with the docker-entrypoint.sh restart flow. Read the MongoDBContainer startup and WaitStrategy handling, then verify that a container using /docker-entrypoint-initdb.d/mongo-init.js starts successfully without manual WaitStrategy customization.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java, mongodb
- Domain
- database, testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100