PanDiMooN
PanDiMooN

Reputation: 43

Connection issue with Mongo database using Intellij and Docker

I have a Mongo database running through Docker but I am unable to connect to it using Intellij.

(I am getting a timeout).

Can you help me? 😃

Error: "java.net.ConnectException: Connection refused: no further information"

Thx 😉

My docker-compose.yml:

version: '3.1'

services:

  mongo:
    image: mongo
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: PanDiMooN
      MONGO_INITDB_ROOT_PASSWORD: PanDiMooN
      MONGO_INITDB_DATABASE: The_Milky_Way

Docker Docker

Timeout err

I tried to restart the container, change ports but I am still getting the timeout.

Upvotes: 1

Views: 1003

Answers (1)

Montgomery Watts
Montgomery Watts

Reputation: 4034

IntelliJ is trying to connect to localhost on port 27017. localhost is how your computer refers to itself in networks. The problem is that your computer isn't listening for requests on this port, a Docker container on your computer is.

To bind requests to port 27017 with your Docker container, you can add a ports section to the compose file:

version: '3.1'

services:

  mongo:
    image: mongo
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: PanDiMooN
      MONGO_INITDB_ROOT_PASSWORD: PanDiMooN
      MONGO_INITDB_DATABASE: The_Milky_Way
    ports:
      - "27017:27017"

Upvotes: 1

Related Questions