title: How to create a mongo database per service with Docker
body: <p>I am working towards having multiple services (NodeJS, Spring-boot) that each have their own MongoDB Database-server-per-service (eventually targeting GCP &amp; K8s) so that I can keep the data separate.  I will be using Docker compose to launch both the service and database together.  However, when I run multiple services, naturally I get port collision.  Here is a typical docker-compose file:</p>
  
  <pre><code>version: '3'
  
  # Define the services/containers to be run
  services:
    myapp: #name of your service
      build: ./ # specify the directory of the Dockerfile
      ports:
        - "3000:3000" #specify ports forwarding
      links:
        - database # link this service to the database service
      volumes:
        - .:/usr/src/app
      depends_on:
        - database
  
    database: # name of the service
      image: mongo # specify image to build container from
      volumes:
          - ./data:/data/db
      ports:
          - "27017:27017"
  </code></pre>
  
  <p>I am looking for an example of how to do this.  My thinking is that each compose file will have it's own ports and each service will map to those ports internally?</p>