Skip to content

Support init scripts for MongoDBContainer without manually customizing the WaitStrategy #3066

Description

@blaluc

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions