Pre setup docker services

I’m having trouble with finding a proper way migrating a mongo service. I could either build a custom image with baked in indexes or install docker in main image and add those indexes during startup.

I think that both ways are kinda sketchy. The first is good because it will work, but i think that such things like adding necessary indexes should be in Makefile.

The second second one is sketchy because Docker image should be as light as possible.

Is there a proper way to access other docker container like the one containing mongo and call the command to ensure the indexes are created?