SpringBoot in Docker not connecting to Mongo in Docker

后端 未结 3 538
醉梦人生
醉梦人生 2021-01-13 10:00

I have a Spring Boot Application and developed it with a mongo db which was running in brew services.

To get a connection to the db I just had to put the following

3条回答
  •  生来不讨喜
    2021-01-13 10:29

    Try the following docker-compose.yml. hostname should fix your problem

    version: '3'
    services:
      mongo:
        container_name: docker-mongo
        image: mongo:latest
        ports:
         - "27017:27017"
        volumes:
         - ./data/db:/data/db
        hostname: mongo
    
     spring:
       depends_on:
        - mongo
       image:docker-spring-http-alpine
       ports:
        - "8080:8080"
       hostname: spring
       links:
        - mongo
    

提交回复
热议问题