'Only run docker container once to populate database

I have a database running in docker and another container that runs a script to populate the database:

stock-trading-system-db:
    container_name: stock-trading-system-db
    image: mongo
    restart: always
    ports:
      - "27017:27017"
    volumes: 
      - ./mongo/data:/data/db
  mongo_seed:
    image: mongo
    links:
      - stock-trading-system-db
    volumes:
      - ./mongo-seed:/mongo-seed
    command:
      mongo-seed/import.sh

I don't want to populate the database every time I launch the containers, how do I make it so it runs the script once and never again?



Solution 1:[1]

You could use this approach containing a startup script which could check inside MongoDB if it was already seeded or not inside your "mongo_seed" service.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 matic1123