connectionMode property

ConnectionMode get connectionMode

Determines the active ConnectionMode for this client.

Resolution order:

  1. TestcontainersConfiguration.connectionModeOverride — explicit override.
  2. If NOT inside a container, or the Docker host is remote → dockerHost.
  3. If inside a container → bridgeIp when the container ID can be determined from cgroups, gatewayIp otherwise.

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;
}