1

I'm trying to launch app with Docker-compose on windows 10 and connect to my MongoDB 3.4 running on the same machine. command to launch app: docker-compose -f src/main/docker/app.yml up

I have an application generated from jhipster and this docker config:

version: '2'
services:
core-app:
    image: core
    environment:
        - SPRING_PROFILES_ACTIVE=prod,swagger
        - EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://admin:$${jhipster.registry.password}@jhipster-registry:8761/eureka
        - SPRING_CLOUD_CONFIG_URI=http://admin:$${jhipster.registry.password}@jhipster-registry:8761/config
        - SPRING_DATA_MONGODB_URI=mongodb://0.0.0.0:27017
        - SPRING_DATA_MONGODB_DATABASE=core
        - JHIPSTER_SLEEP=10 # gives time for the JHipster Registry to boot before the application
jhipster-registry:
    extends:
        file: jhipster-registry.yml
        service: jhipster-registry
    environment:
        - SPRING_CLOUD_CONFIG_SERVER_NATIVE_SEARCH_LOCATIONS=file:./central-config/docker-config/

i have an exception:

MongoSocketException: mongodb://0.0.0.0:27017}, caused by {java.net.UnknownHostException: mongodb://0.0.0.0:27017

how to fix this? Any other guides don't work

Igor
  • 478
  • 9
  • 22

1 Answers1

0

If you are running Mongo without going through docker/docker-compose, its hosted on your localhost.

You cant really reveal localhost from host to a docker container just like that (without using network --host option which isn't recommended).

I would suggest you create a service for mongodb inside docker-compose file and link it to your main service.

Jaskaranbir Singh
  • 2,034
  • 3
  • 17
  • 33
  • Thanks fo your answer. Can you explain what you mean by creating a service? new container with mongodb image ? – Igor Oct 30 '17 at 17:11
  • Yes, new container with mongodb image. And add a `service` for MongoDB under `services` section of your docker-compose file. Just like you did with creating `core-app` service. If you want to research around, you should probably look for how to use mongodb with docker-compose. – Jaskaranbir Singh Oct 30 '17 at 17:20
  • i want to use my own DB, that is lauched in my system. Any options to do this? – Igor Oct 30 '17 at 17:28
  • You can use `--net=host` to use host network, and the mongodb service should be available. However, that's unrecommended. If you can, create some script or use some tool to seed the mongo to whatever initial state you require. Feel free to read this: https://stackoverflow.com/questions/43316376/what-does-net-host-option-in-docker-command-really-do For how to do this in docker-compose, check out `network-mode`: https://docs.docker.com/compose/compose-file/#network_mode – Jaskaranbir Singh Oct 30 '17 at 17:44