title: MongoDB init-script not launching with docker-compose
body: <p>I did setup a docker-compose file that connects my app to a mongoDB database. My problem is that the database seems to never be initialized at first. My script is not executed and even tho' I can send some requests to the container, I only get connection refused errors due to authentification.</p>
  
  <p>I did follow exactly this <a href="https://stackoverflow.com/questions/42912755/how-to-create-a-db-for-mongodb-container-on-start-up?noredirect=1&amp;lq=1">thread</a> and I don't know what I'm missing out! (the <code>db</code> folder is on the same level as my <code>docker-compose.yml</code>)</p>
  
  <p>Looking for some help on this one, thanks!</p>
  
  <p>edit: None of the logs I did put in the init script are showing in the console, that's how I went to the conclusion that the file is not executed at all.</p>
  
  <p>Here is my docker-compose file:</p>
  
  <pre><code>
  services:
    mongo:
      image: mongo:latest
      restart: always
      environment:
        MONGO_INITDB_ROOT_USERNAME: admin
        MONGO_INITDB_ROOT_PASSWORD: admin
        MONGO_INITDB_DATABASE: test
      volumes:
        - ./db:/docker-entrypoint-initdb.d
        - ./db-data:/data/db
      ports:
        - 27017:27017
      networks:
        - api1
  
    app:
      restart: always
      build:
        context: .
      environment:
        DB_HOST: localhost
        DB_PORT: 27017
        DB_NAME: test
        DB_USER: developer
        DB_PASS: developer
        PORT: 3000
      ports:
        - 3000:3000
      networks:
        - api1
      depends_on:
        - mongo
      command: npm start
  networks:
    api1:
      driver: bridge
  </code></pre>
  
  <p>Here is my init scipt:</p>
  
  <pre><code>/* eslint-disable no-undef */
  
  try {
    print("CREATING USER")
    db.createUser(
      {
        user: "developer",
        pwd: "developer",
        roles: [{ role: "readWrite", db: "test" }]
      }
    );
  } catch (error) {
    print(`Failed to create developer db user:\n${error}`);
  }
  </code></pre>
  
  <p>And my dockerfile:</p>
  
  <pre><code>FROM node:10 as builder
  
  RUN mkdir /home/node/app
  WORKDIR /home/node/app
  
  # Install dependencies
  COPY package.json yarn.lock ./
  RUN yarn install &amp;&amp; yarn cache clean
  
  # Copy source scripts
  COPY . .
  
  RUN yarn build
  
  FROM node:10-alpine
  
  RUN mkdir -p /home/node/app
  WORKDIR /home/node/app
  
  COPY --from=builder --chown=node:node /home/node/app .
  
  USER node
  EXPOSE 3000
  CMD ["node", "./build/bundle.js"]
  </code></pre>