title: Docker compose for Zookeeper and Spring Cloud - my service does not connect to zoo
body: <p>I'm trying to run zookeeper and spring cloud service inside a container using docker-compose. When I run the service The jar file and start the zoo everything is fine. But, when I'm trying to run in a container The service cannot connect to zoo -</p>
  <p>Here is the error when docker-compose up:</p>
  <pre><code>controller_1  | 2020-07-21 09:45:12.715  WARN 1 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn          : Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
  controller_1  |
  controller_1  | java.net.ConnectException: Connection refused
  controller_1  |         at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.8.0_111-internal]
  controller_1  |         at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) ~[na:1.8.0_111-internal]
  controller_1  |         at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361) ~[zookeeper-3.4.8.jar!/:3.4.8--1]
  controller_1  |         at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141) ~[zookeeper-3.4.8.jar!/:3.4.8--1]
  controller_1  |
  </code></pre>
  <p>Here is my yaml.file</p>
  <pre><code>version: '3'
  services:
    zookeeper:
      image: 'zookeeper:3.4'
      ports:
        - &quot;2181:2181&quot;
      restart: always
      container_name: zookeeper
      environment:
        ZOOKEEPER_SASL_ENABLED: 'FALSE'
        
    controller:
      build: distributed-search-engine-1/
      ports:
        - &quot;8083:8083&quot;
      links:
        - zookeeper
      depends_on: 
        - zookeeper
  </code></pre>
  <p>Docker file of the service:</p>
  <pre><code>FROM java:8-jdk-alpine
  COPY ./build/libs/distributed-search-engine-1-0.0.1-SNAPSHOT.jar /usr/app/
  WORKDIR /usr/app
  EXPOSE 8083
  ENTRYPOINT [&quot;java&quot;, &quot;-jar&quot;, &quot;distributed-search-engine-1-0.0.1-SNAPSHOT.jar&quot;]
  </code></pre>
  <p>My service does not define any Zookeeper port, so I guess 2181 should be fine. anyway, here is my build file:</p>
  <pre><code>buildscript {
      ext {
          springBootVersion = '2.0.0.RELEASE'
      }
      repositories {
          mavenCentral()
      }
      dependencies {
          classpath(&quot;org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}&quot;)
      }
  }
  
  apply plugin: 'java'
  apply plugin: 'eclipse'
  apply plugin: 'org.springframework.boot'
  apply plugin: 'io.spring.dependency-management'
  
  group = 'com.search'
  version = '0.0.1-SNAPSHOT'
  sourceCompatibility = 1.8
  
  repositories {
      mavenCentral()
      maven { url &quot;https://repo.spring.io/milestone&quot; }
  }
  
  
  ext {
      springCloudVersion = 'Finchley.M8'
  }
  
  dependencies {
      compile(&quot;org.springframework.boot:spring-boot-starter-web&quot;)
      compile('org.springframework.boot:spring-boot-starter-actuator')
      compile('org.springframework.boot:spring-boot-starter-integration')
      compile group: 'org.springframework.integration', name: 'spring-integration-zookeeper'
      compile('org.springframework.cloud:spring-cloud-starter-zookeeper-config')
  
      testCompile('org.springframework.boot:spring-boot-starter-test')
  }
  
  dependencyManagement {
      imports {
          mavenBom &quot;org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}&quot;
      }
  }
  
  
  
  jar {
    manifest { 
      attributes &quot;Main-Class&quot;: &quot;com.search.server.Application&quot;
    }  
  
    from {
      configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
  }
  
  
  
  
  </code></pre>
  <p>Thanks!!!!</p>