Skip to content

Commit

Permalink
43581 define host.docker.internal with 19092 port for network communi…
Browse files Browse the repository at this point in the history
…cation with a kafka connect (likes Debezium) devservice
  • Loading branch information
dcdh committed Sep 29, 2024
1 parent 2811eec commit e8fff2f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class KafkaNativeContainer extends GenericContainer<KafkaNativeContainer>
private int exposedPort = -1;

private String hostName = null;
private static final String HOST_DOCKER_INTERNAL = "host.docker.internal";
private static final int HOST_DOCKER_INTERNAL_PORT = 19092;

public KafkaNativeContainer(DockerImageName dockerImageName, int fixedExposedPort, String serviceName,
boolean useSharedNetwork) {
Expand All @@ -47,7 +49,7 @@ protected void containerIsStarting(InspectContainerResponse containerInfo, boole
cmd += "/work/kafka";
cmd += " -Dkafka.advertised.listeners=" + getBootstrapServers();
if (useSharedNetwork) {
cmd += " -Dkafka.listeners=BROKER://:9093,PLAINTEXT://:9092,CONTROLLER://:9094";
cmd += " -Dkafka.listeners=BROKER://:9093,PLAINTEXT://:9092,CONTROLLER://:9094,HOST_DOCKER_INTERNAL://"+HOST_DOCKER_INTERNAL_PORT;
cmd += " -Dkafka.interbroker.listener.name=BROKER";
cmd += " -Dkafka.controller.listener.names=CONTROLLER";
cmd += " -Dkafka.listener.security.protocol.map=BROKER:PLAINTEXT,CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT";
Expand All @@ -74,6 +76,9 @@ private String getKafkaAdvertisedListeners() {
// See https://github.com/quarkusio/quarkus/issues/21819
// Kafka is always exposed to the Docker host network
addresses.add(String.format("PLAINTEXT://%s:%d", getHost(), getExposedKafkaPort()));
// See https://github.com/debezium/debezium/pull/5903
// need to access kafka from a debezium connect container using
addresses.add(String.format("HOST_DOCKER_INTERNAL://%s:%d", HOST_DOCKER_INTERNAL, getMappedPort(HOST_DOCKER_INTERNAL_PORT)));
return String.join(",", addresses);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ final class RedpandaKafkaContainer extends GenericContainer<RedpandaKafkaContain

private static final String STARTER_SCRIPT = "/var/lib/redpanda/redpanda.sh";
private static final int PANDAPROXY_PORT = 8082;
private static final String HOST_DOCKER_INTERNAL = "host.docker.internal";
private static final int HOST_DOCKER_INTERNAL_PORT = 19092;

RedpandaKafkaContainer(DockerImageName dockerImageName, int fixedExposedPort, String serviceName,
boolean useSharedNetwork, RedpandaBuildTimeConfig redpandaConfig) {
Expand Down Expand Up @@ -79,6 +81,9 @@ private String getKafkaAddresses() {
// See https://github.com/quarkusio/quarkus/issues/21819
// Kafka is always available on the Docker host network
addresses.add("OUTSIDE://0.0.0.0:9092");
// See https://github.com/debezium/debezium/pull/5903
// need to access kafka from a debezium connect container using
addresses.add("HOST_DOCKER_INTERNAL://0.0.0.0:" + HOST_DOCKER_INTERNAL_PORT);
return String.join(",", addresses);
}

Expand All @@ -90,6 +95,9 @@ private String getKafkaAdvertisedAddresses() {
// See https://github.com/quarkusio/quarkus/issues/21819
// Kafka is always exposed to the Docker host network
addresses.add(String.format("OUTSIDE://%s:%d", getHost(), getMappedPort(DevServicesKafkaProcessor.KAFKA_PORT)));
// See https://github.com/debezium/debezium/pull/5903
// need to access kafka from a debezium connect container using
addresses.add(String.format("HOST_DOCKER_INTERNAL://%s:%d", HOST_DOCKER_INTERNAL, getMappedPort(HOST_DOCKER_INTERNAL_PORT)));
return String.join(",", addresses);
}

Expand Down

0 comments on commit e8fff2f

Please sign in to comment.