title: com.mongodb.MongoSocketOpenException: Exception opening socket(MongoDB, Docker)
body: <p>I try to starting my application(Spring Boot + Spring Cloud + Eureka + MongoDB) with using docker image, but i can't get connection to MongoDB.</p>
  
  <p><strong>Exception:</strong></p>
  
  <pre><code>exception "com.mongodb.MongoSocketOpenException: Exception opening socket."
  </code></pre>
  
  <p>I starting my application with execute command: <em>docker-compose up --build</em></p>
  
  <p><strong>Docker log:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/D2gfo.png" rel="noreferrer"><img src="https://i.stack.imgur.com/D2gfo.png" alt="enter image description here"></a></p>
  
  <p><strong>application.yml:</strong></p>
  
  <pre><code># Spring properties
  spring:
    application:
      name: car-service
    data:
      mongodb.host: localhost
      mongodb.port: 32769
      mongodb.uri: mongodb://localhost/test
      mongo.repositories.enabled: true
  
  
  # Discovery Server Access
  eureka:
      client:
        serviceUrl:
          defaultZone: http://localhost:8761/eureka/
  
  # HTTP Server (Tomcat) Port
  server: 
    port: 2220
  
  error:
    whitelabel:
      enabled: false
  </code></pre>
  
  <p><strong>docker-compose.yml:</strong></p>
  
  <pre><code>eureka:
    build: ./eureka-discovery-service
    ports:
      - "8761:8761"
  
  mongodb:
    image: mongo:3.0.4
    ports:
      - "32769:32769"
  
  postgresql:
    image: postgres:9.6.1
    ports:
      - "32770:32770"
  
  gateway-service:
    build: ./gateway-service
    ports:
      - "9090:9090"
    links:
      - eureka
    environment:
      SPRING_APPLICATION_NAME: gateway-service
      SPRING_PROFILES_ACTIVE: enableEureka
      EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
      EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
  
  airplane-service:
    build: ./airplane-service
    ports:
      - "2222:2222"
    links:
      - eureka
      - postgresql
    environment:
      SPRING_APPLICATION_NAME: airplane-service
      SPRING_PROFILES_ACTIVE: enableEureka
      EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
      EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
      SPRING_SLEUTH_ENABLED: "true"
      SPRING_DATASOURCE_POSTGRESQL_URL: jdbc:postgresql://localhost:32770/postgres
  
  car-service:
    build: ./car-service
    ports:
      - "2220:2220"
    links:
      - eureka
      - mongodb
    environment:
      SPRING_APPLICATION_NAME: car-service
      SPRING_PROFILES_ACTIVE: enableEureka
      EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
      EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
      SPRING_SLEUTH_ENABLED: "true"
      SPRING_DATA_MONGODB_URI: mongodb://localhost:32769/test
  
  
  machine-service:
    build: ./machine-service
    ports:
      - "2224:2224"
    links:
      - eureka
    environment:
      SPRING_APPLICATION_NAME: machine-service
      SPRING_PROFILES_ACTIVE: enableEureka
      EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
      EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
      SPRING_SLEUTH_ENABLED: "true"
  </code></pre>
  
  <p>Why I have exception opening a socket? How to fix this problem?</p>