@Override
    @SneakyThrows
    public void start() {
        // sequential start to avoid resource contention on CI systems with weaker hardware
        brokers.forEach(GenericContainer::start);

        Awaitility
            .await()
            .atMost(Duration.ofSeconds(30))
            .untilAsserted(() -> {
                Container.ExecResult result =
                    this.zookeeper.execInContainer(
                            "sh",
                            "-c",
                            "zookeeper-shell zookeeper:" +
                            KafkaContainer.ZOOKEEPER_PORT +
                            " ls /brokers/ids | tail -n 1"
                        );
                String brokers = result.getStdout();

                assertThat(brokers.split(",")).hasSize(this.brokersNum);
            });
    }
Provides an easy way to launch a Kafka cluster with multiple brokers.
examples/kafka-cluster/src/test/java/com/example/kafkacluster/KafkaContainerCluster.java