host property
String
get
host
Returns the host address used to reach containers.
Resolution order:
- TestcontainersConfiguration.tcHostOverride (explicit override).
- SSH Docker host hostname extracted by dockerHostHostname.
- Hostname from a
tcp://,http://, orhttps://DOCKER_HOSTURL. On Windows, Docker's named-pipe hostlocalnpipeis normalised to'localhost'. - Default gateway IP when running inside a container (defaultGatewayIp).
'localhost'as the final fallback.
Implementation
String get host {
final override = testcontainersConfig.tcHostOverride;
if (override != null) {
return override;
}
final sshHost = dockerHostHostname();
if (sshHost != null) {
return sshHost;
}
final rawHost = dockerHost();
if (rawHost != null) {
if (rawHost.startsWith('tcp://') ||
rawHost.startsWith('http://') ||
rawHost.startsWith('https://')) {
final uri = Uri.parse(rawHost);
final h = uri.host;
if (h.isEmpty || (h == 'localnpipe' && isWindows())) {
return 'localhost';
}
return h;
}
}
if (insideContainer()) {
final gw = defaultGatewayIp();
if (gw != null) {
return gw;
}
}
return 'localhost';
}