0

i try to dockerize my apps and i am tryimng to start 3 containers with docker compose. My docker-compose:

version: '3'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
    - "2181:2181"
  kafka:
    image: wurstmeister/kafka
    ports:
    - "9092:9092"
    depends_on:
       - zookeeper
    healthcheck:
      test: nc -z localhost 9092 || exit -1
      start_period: 15s
      interval: 5s
      timeout: 10s
      retries: 10
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 127.0.0.1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false' 
  humanresources:
      image: univer-anu4/humanresources:latest
      ports:
       - "8081:8081"
      depends_on:
        kafka:
          condition: service_healthy
      deploy:
        restart_policy:
          condition: on-failure
          delay: 10s
          max_attempts: 3
          window: 30s  

The problem is that i get this error each time i staty docvker compose up:

compose-humanresources-1  | 2022-11-19 09:14:59.941  WARN 1 --- [| adminclient-1] org.apache.kafka.clients.NetworkClient   : [AdminClient clientId=adminclient-1] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.

But if i remove my service hu7manresources from docker compose and starting only zookeper and kafka containers then app from intelijidee its starting properly. Do you guys have some ideea why this happening?

My application.properties:

spring.h2.console.enabled=true

spring.datasource.url=jdbc:h2:mem:DB
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.kafka.template.default-topic=pad2
eureka.client.service-url.defaultZone = http://localhost:7080/eureka/
kafka.bootstrapAddress = localhost:9092
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.flyway.locations=classpath:db/migration
spring.flyway.enabled=true
spring.application.name=hr

eureka.instance.prefer-ip-address=true
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.instance.lease-renewal-interval-in-seconds=30
spring.kafka.consumer.group-id=${random.uuid}
  • Can‘t see the error, cause it‘s an image but dependency in docker compose is limited to starting a container. It does not wait for the application in that container to start. If required, you need to use some kind of „wait-for“ script as entrypoint at your depending containers. – Christoph Dahlen Nov 19 '22 at 09:05
  • I edited , now you can see the error – Gumaniuc Alexandru Nov 19 '22 at 09:15
  • 1
    `kafka.bootstrapAddress = localhost:9092` - I think this needs to be `kafka:9092`, as the server is not running in you application‘s container (though both are running on your localhost). – Christoph Dahlen Nov 19 '22 at 12:51
  • Yes. Localhost refers to the spring app, not the Kafka container – OneCricketeer Nov 19 '22 at 13:15
  • Also, it's `spring.kafka.bootstrap-servers` https://docs.spring.io/spring-boot/docs/current/reference/html/messaging.html#messaging.kafka – OneCricketeer Nov 19 '22 at 13:16

0 Answers0