Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose host.docker.internal to Kafka DevService #43582

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,8 @@ 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 +77,10 @@ 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,10 @@ 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