Skip to content
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 @@ -50,7 +50,9 @@ public class KafkaSchemaRegistryResource extends TestcontainerResource<RedpandaC
protected RedpandaContainer createContainer()
{
return new RedpandaContainer(SCHEMA_REGISTRY_IMAGE)
.dependsOn(kafkaResource.getContainer());
.dependsOn(kafkaResource.getContainer())
// Enable host.docker.internal on Linux (Docker Desktop provides this automatically)
.withExtraHost("host.docker.internal", "host-gateway");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ public K3sClusterResource usingDruidManifestTemplate(String resourceName)
protected K3sContainer createContainer()
{
Objects.requireNonNull(druidImageName, "No Druid image specified");
final K3sContainer container = new K3sContainer(DockerImageName.parse(K3S_IMAGE_NAME));
final K3sContainer container = new K3sContainer(DockerImageName.parse(K3S_IMAGE_NAME))
// Enable host.docker.internal on Linux (Docker Desktop provides this automatically)
.withExtraHost("host.docker.internal", "host-gateway");

final List<String> portBindings = new ArrayList<>();
for (K3sDruidService service : services) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public DruidContainer(DruidCommand command, DockerImageName imageName)
port -> port + ":" + port
).collect(Collectors.toList());
setPortBindings(portBindings);

// Enable host.docker.internal on Linux (Docker Desktop provides this automatically)
withExtraHost("host.docker.internal", "host-gateway");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,19 @@ public void beforeStart(EmbeddedDruidCluster cluster)
@Override
protected KafkaContainer createContainer()
{
// The result of getBootstrapServers() is the first entry in KafkaContainer.advertisedListeners.
// Override getBootstrapServers() to ensure that both DruidContainers and
// EmbeddedDruidServers can connect to the Kafka brokers.
return new KafkaContainer(KAFKA_IMAGE) {
@Override
public String getBootstrapServers()
{
return cluster.getEmbeddedHostname().useInHostAndPort(super.getBootstrapServers());
}
};
return new KafkaContainer(KAFKA_IMAGE)
// Enable host.docker.internal on Linux (Docker Desktop provides this automatically)
.withExtraHost("host.docker.internal", "host-gateway");
}

/**
* Returns the Kafka bootstrap server URL, transformed using the cluster's
* embedded hostname so it's reachable from both embedded and containerized services.
*/
public String getBootstrapServerUrl()
{
ensureRunning();
return getContainer().getBootstrapServers();
return cluster.getEmbeddedHostname().useInHostAndPort(getContainer().getBootstrapServers());
}

public Map<String, Object> consumerProperties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@

import com.google.common.net.HostAndPort;
import org.apache.druid.java.util.common.IAE;
import org.apache.druid.java.util.common.ISE;
import org.apache.http.client.utils.URIBuilder;
import org.testcontainers.DockerClientFactory;

import java.net.InetAddress;
import java.net.URISyntaxException;
import java.net.UnknownHostException;

/**
* Hostname to be used by embedded services, both Druid and external.
Expand All @@ -53,18 +51,20 @@ public static EmbeddedHostname localhost()
}

/**
* Hostname for the host machine running the containers. When a service uses
* this hostname instead of {@link #localhost}, it is reachable by Druid
* containers and EmbeddedDruidServers alike.
* Returns an EmbeddedHostname that is reachable from both embedded services
* (running on the host JVM) and containerized services (running in Docker).
* <p>
* On Linux, this returns the Docker bridge gateway IP (e.g., {@code 172.17.0.1})
* which is routable from both the host and containers.
* <p>
* Note: On Mac/Windows with Docker Desktop, this returns {@code localhost}
* which only works for embedded services. Tests mixing embedded and containerized
* services should run on Linux.
*/
public static EmbeddedHostname containerFriendly()
{
try {
return new EmbeddedHostname(InetAddress.getLocalHost().getHostAddress());
}
catch (UnknownHostException e) {
throw new ISE(e, "Unable to determine host name");
}
String dockerHostIp = DockerClientFactory.instance().dockerHostIpAddress();
return new EmbeddedHostname(dockerHostIp);
}

/**
Expand Down
Loading