title: Docker Compose MongoDB docker-entrypoint-initdb.d is not working
body: <p>I am using following docker-compose file </p>
  
  <pre><code>version: '3.7'
  services:
   db_container:
    image: mongo:latest
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: password
      MONGO_INITDB_DATABASE: root-db
    ports:
      - 27017:27017
    volumes:
      - ./database/initdb.js:/docker-entrypoint-initdb.d/initdb.js:ro
      - ./data:/data/db
  </code></pre>
  
  <p>Here is my initdb.js file</p>
  
  <pre><code>db.createUser(
  {
    user: "api-test",
    pwd: "api-test",
    roles: [
      {
        role: "readWrite",
        db: "api-test"
      }
    ]
  }
  );
  </code></pre>
  
  <p>I can see only 3 databases  and unable to connect to <code>api-test</code> DB</p>
  
  <p><a href="https://i.stack.imgur.com/xWqyy.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xWqyy.png" alt="enter image description here"></a></p>
  
  <p>Please help me if something is missing</p>