1

I am new to the docker container and docker-compose.

I am creating a chat microservice with MongoDB and Docker with docker-compose but I can't connect with MongoDB compass. Here below my docker-compose file:

    version: "3"
    services:
      chat-service:
        build: "./chat-service"
      depends_on: 
        - chat-service-db
      volumes:
        - ./chat-service:/opt/app

    chat-service-db:
       environment:
         - MONGO_INITDB_ROOT_USERNAME=root
         - MONGO_INITDB_ROOT_PASSWORD=password
         - MONGO_INITDB_DATABASE=chatservice
       image: mongo
       ports:
         - 0.0.0.0:27017:27017

    user-service:
      build: "./user-service"
      depends_on: 
        - user-service-db
      volumes:
        - ./user-service:/opt/app

    user-service-db:
      environment:
        - MONGO_INITDB_ROOT_USERNAME=root
        - MONGO_INITDB_ROOT_PASSWORD=password
        - MONGO_INITDB_DATABASE=userservice
     image: mongo
     ports:
       - 0.0.0.0:27018:27017
m19v
  • 1,800
  • 4
  • 11
  • 26
Kartik Fulara
  • 45
  • 3
  • 7

1 Answers1

0

Check that you aren't use the same port for others process, if you're on windows use the command

netstat -aon | findstr "27017"

That shows you what process is listening on port 27017, and you have to finish them, for finish them use the command

taskkill /F /PID <PID>

The PID is the last number in the list that show the first command.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459