ruanbekker / quick-starts

Collection of quick starts on docker, terraform, ansible, etc
https://quickstarts.ruan.dev/
16 stars 8 forks source link

Shell doesn't work with Docker Compose #37

Closed gilbertotcc closed 6 months ago

gilbertotcc commented 6 months ago

I'm having some issues in running shell commands on the Kafka cluster defined in https://github.com/ruanbekker/quick-starts/blob/main/docker/kafka/docker-compose.yaml.

Consumer and producer correctly work and Kafka cluster works too, but if I try to run a Docker container with:

$ docker run -it --name kafla-cli --network kafka confluentinc/cp-kafka bash

and try this:

$ kafka-topics --list --bootstrap-server broker-1:9091

I get these errors:

[2024-04-06 15:03:19,359] WARN [AdminClient clientId=adminclient-1] Connection to node 1 (localhost/127.0.0.1:9091) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2024-04-06 15:03:19,361] WARN [AdminClient clientId=adminclient-1] Connection to node 2 (localhost/127.0.0.1:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2024-04-06 15:03:19,361] WARN [AdminClient clientId=adminclient-1] Connection to node 3 (localhost/127.0.0.1:9093) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2024-04-06 15:03:19,462] WARN [AdminClient clientId=adminclient-1] Connection to node 1 (localhost/127.0.0.1:9091) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

From the shell (within the docker container) I can correctly ping the nodes. E.g.

[appuser@14b87f3a1ce1 ~]$ ping broker-3
PING broker-3 (172.18.0.5) 56(84) bytes of data.
64 bytes from broker-3.kafka (172.18.0.5): icmp_seq=1 ttl=64 time=0.202 ms
64 bytes from broker-3.kafka (172.18.0.5): icmp_seq=2 ttl=64 time=0.178 ms

I'm using Docker on macOS and it seems that the problem could be on the DNS. But I couldn't find the solution.

gilbertotcc commented 6 months ago

I was pointing to the wrong ports.

Using broker-1:29091,broker-2:29092,broker-3:29093 works.