connectionMode property
ConnectionMode
get
connectionMode
Determines the active ConnectionMode for this client.
Resolution order:
- TestcontainersConfiguration.connectionModeOverride — explicit override.
- If NOT inside a container, or the Docker host is remote →
dockerHost. - If inside a container →
bridgeIpwhen the container ID can be determined from cgroups,gatewayIpotherwise.
Implementation
ConnectionMode get connectionMode {
final override = testcontainersConfig.connectionModeOverride;
if (override != null) {
return override;
}
const localhosts = {'localhost', '127.0.0.1', '::1'};
if (!insideContainer() || !localhosts.contains(host)) {
return ConnectionMode.dockerHost;
}
final containerId = runningContainerId();
if (containerId != null) {
return ConnectionMode.bridgeIp;
}
return ConnectionMode.gatewayIp;
}