Docker-compose Spring boo and MongoDB: Connection Refused

1

I'm studying docker, and I'm trying to run a small application made in Springboot along with Mongodb in a single container.

I wrote the following Dockerfile:

FROM openjdk:8-jre-alpine

ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
JAVA_OPTS=""

ADD /target/*.jar /app.jar

EXPOSE 8080

CMD java ${JAVA_OPTS} -jar /app.jar

I also did a docker-compose.yml

version: "2"

services:
  mongodb:
    image: mongo
    ports:
      - "27017:27017"

 springapp:
   build: .
   depends_on:
     - mongodb
   ports:
     - 8080:8080
   links:
     - mongodb  

When I start the application, I get "Connection Refused". Below is my application.yml:

spring:
  data:
    monbodb:
      host: mongodb
      port: 27017
      database: customer

This example of docker-compose.yml I got in the documentation, however I still have not figured out what I'm doing wrong.

Many thanks for the strength:)

    
asked by anonymous 06.11.2017 / 21:38

1 answer

0

I made some changes to docker-compose.yml and it worked:

version: "3"
services:
   mongodb:
     container_name: sample-datastore
     image: mongo
   springapp:
     container_name: sample-app
     build: .
     depends_on:
       - mongodb
     ports:
       - 8080:8080
     links:
       - mongodb
     environment:
       SPRING_DATA_MONGODB_URI: mongodb://mongodb/customer

Basically, I have removed the port settings, and I set the Bank URI as the application parameter, so it is not necessary to mark any configuration of the database in Application.yml! I do not know if this is the best way, but you answered my problem. :)

    
06.11.2017 / 22:06