testcontainers/testcontainers-java

Support init scripts for `MongoDBContainer` without manually customizing the `WaitStrategy`

Open

#3,066 opened on 2020年8月1日

GitHub で見る
 (16 comments) (1 reaction) (0 assignees)Java (7,535 stars) (1,588 forks)batch import
good first issuemodules/mongodbtype/feature

説明

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"
...

コントリビューターガイド