Docker compose seeding with createSearchIndex fails with MongoServerError

I have the following docker compose file:

services:
  mongo:
    image: mongodb/mongodb-atlas-local:8.0
    environment:
      - MONGO_LOG_LEVEL=DEBUG
      - MONGO_VERBOSE=1
      - MONGOT_LOG_FILE=/dev/stdout
      - RUNNER_LOG_FILE=/dev/stdout
    volumes:
      - ./docker-compose/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d:ro
    ports:
      - "27017:27017"

My init script init.js looks like this:

db = db.getSiblingDB('test');
db.createCollection('personen');
db.personen.insertMany([
    {"name": "Hans Hansen", "email": "hans.hansen@example.com"},
    {"name": "Gerda Grün", "email": "gg@example.com"}
]);
db.personen.createSearchIndex(
    "testSearchIndex",
    { mappings: { dynamic: true } }
);

When the docker container starts I see the following error message on the console:

{“time”:“2024-11-26T22:36:31.352382037Z”,“level”:“DEBUG”,“msg”:“MongoServerError: Using Atlas Search Database Commands and the $listSearchIndexes aggregation stage requires additional configuration. Please connect to Atlas or an AtlasCLI local deployment to enable. For more information on how to connect, see https://dochub.mongodb.org/core/atlas-cli-deploy-local-reqs.“,“file”:”/docker-entrypoint-initdb.d/init.js”}

What can I do to get this local setup running?

I should add that when i remove the following part from init.js then the mongodb container starts without a problem.

db.personen.createSearchIndex(
    "testSearchIndex",
    { mappings: { dynamic: true } }
);

After the mongodb container is running I can add a search index over curl for example:

mongosh mongodb://localhost:27017/test --eval "db.personen.createSearchIndex('testSearchIndex', {'mappings':{'dynamic': true}})"

But why can’t I add the search index create into the init.js? What is the error message telling me?