Scilla
Scilla

Reputation: 1

Dockerizing SpringBoot Mongo Exception opening socket

I am trying to dockerize my spring boot and mongo.

This is my application.yml

spring:
  application:
    name: service-app
  data:
    mongodb:
      uri: mongodb://localhost:27017/user

I have found this to be recommended in other posts.

The error I get is:

  Exception in monitor thread while connecting to server localhost:27017
  com.mongodb.MongoSocketOpenException: Exception opening socket
        at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) ~. 
  [mongodb-driver-core-4.1.1.jar:na]

version: '3'
services:
  mongo:
    image: library/mongo:latest
    container_name: mongo
    restart: always
    ports:
      - 27017:27017
    network_mode: host
    volumes:
      - $HOME/mongo:/data/db
    healthcheck:
      test: "exit 0"

  user-service:
    build:
      context: .
      dockerfile: Dockerfile
    image: user-service
    depends_on:
      - mongo
    network_mode: "host"
    hostname: localhost
    restart: always
    ports:
      - 8082:8082
    healthcheck:
      test: "exit 0"

FROM openjdk:8-jdk-alpine

ADD ./target/demo-0.0.1-SNAPSHOT.jar /usr/src/user-service-0.0.1-SNAPSHOT.jar

WORKDIR usr/src

ENTRYPOINT ["java -Djdk.tls.client.protocols=TLSv1.2","-jar", "user-service-0.0.1-SNAPSHOT.jar"]

It seems to be a common problem for noobsters, I couldn't solve it with what was on the internet already.

Upvotes: 1

Views: 211

Answers (0)

Related Questions