0

On my repository I have run docker-compose up -d on the root directory and I am checking the myapp container logs. The producer and consumer Python files are unable to connect to the Kafka broker, prompting the error:

Failed to resolve 'broker:29092'

In my docker-compose.yml file, you'll notice that I have the following line on the Kafka container (I'm using the confluent Kafka image https://hub.docker.com/r/confluentinc/cp-kafka/).

      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092

From my limited understanding of networks, this line tells that the external host must connect to localhost:9092, whereas internal hosts should connect to broker:29092.

Since I'm trying to connect from the inside, my producer.py file uses broker:29082 as the bootstrap.server, same for the consumer.py. However, for some unknown reason, the connection is not being established. How can I overcome this problem?

p=Producer({'bootstrap.servers':'broker:29092'})
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • 1
    Please [edit] the question and include all relevant details in the question itself. (If you resolve your issue and update your repository, then just cloning the now-fixed repo won't demonstrate the issue.) – David Maze Nov 20 '22 at 02:57
  • `Failed to resolve ` means you have a generic network issue. Not Kafka related (which your code is fine). You can start any container in your custom Docker network and try to `ping broker`. – OneCricketeer Nov 20 '22 at 13:36
  • Typo. Your container isn't called `broker`. Fix your environment variables appropriately. https://github.com/Quilograma/IES_Project/blob/main/docker-compose.yml#L13-L15 – OneCricketeer Nov 20 '22 at 13:40
  • 1
    When posting here, show your Docker Compose config, and the log output, in code blocks. Links to repositories won't do. Thanks! – halfer Nov 20 '22 at 13:44

0 Answers0