{"record":{"id":"66ad6ee304bc58ce","repo":"testcontainers/testcontainers-java","slug":"can-t-parse-the-default-gateway-ip","errorCode":null,"errorMessage":"Can't parse the default gateway IP","messagePattern":"Can't parse the default gateway IP","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/src/main/java/org/testcontainers/dockerclient/DockerClientConfigUtils.java","lineNumber":38,"sourceCode":"    private static final Optional<String> defaultGateway = Optional\n        .ofNullable(\n            DockerClientFactory\n                .instance()\n                .runInsideDocker(\n                    cmd -> cmd.withCmd(\"sh\", \"-c\", \"ip route|awk '/default/ { print $3 }'\"),\n                    (client, id) -> {\n                        try {\n                            LogToStringContainerCallback loggingCallback = new LogToStringContainerCallback();\n                            client\n                                .logContainerCmd(id)\n                                .withStdOut(true)\n                                .withFollowStream(true)\n                                .exec(loggingCallback)\n                                .awaitStarted();\n                            loggingCallback.awaitCompletion(3, TimeUnit.SECONDS);\n                            return loggingCallback.toString();\n                        } catch (Exception e) {\n                            log.warn(\"Can't parse the default gateway IP\", e);\n                            return null;\n                        }\n                    }\n                )\n        )\n        .map(StringUtils::trimToEmpty)\n        .filter(StringUtils::isNotBlank);\n\n    /**\n     * @deprecated use {@link DockerClientProviderStrategy#getDockerHostIpAddress()}\n     */\n    @Deprecated\n    public static String getDockerHostIpAddress(URI dockerHost) {\n        switch (dockerHost.getScheme()) {\n            case \"http\":\n            case \"https\":\n            case \"tcp\":\n                return dockerHost.getHost();","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/dockerclient/DockerClientConfigUtils.java#L20-L56","documentation":"DockerClientConfigUtils (in its docker-host gateway detection code) tries to determine the default gateway IP by exec'ing a command in a helper container and parsing the output. If that execution or parse throws, it logs 'Can't parse the default gateway IP' and returns null/empty, meaning Testcontainers cannot compute the docker host address used to reach exposed ports from the container.","triggerScenarios":"Running the gateway-IP detection (Optional.rawInspect etc. in DockerClientConfigUtils, triggered when building a config for a remote/docker-machine style host) where the exec on the logging callback fails or throws any Exception.","commonSituations":"Docker environments without a resolvable default gateway (custom networks, rootless/VM setups, Docker Toolbox/legacy docker-machine), restricted environments where the helper container cannot run, or DNS/network misconfiguration on the daemon host.","solutions":["Ensure the Docker daemon host has a normal default gateway and the container network can reach it.","Set the docker host explicitly (DOCKER_HOST env var or withDockerHost) so Testcontainers doesn't have to guess the gateway.","Upgrade Testcontainers — newer versions use better gateway detection (docker-java network inspect).","If on legacy docker-machine/Toolbox, migrate to Docker Desktop or a supported Linux daemon."],"exampleFix":"// before\nDefaultDockerClientConfig.createDefaultConfigBuilder().build(); // relies on gateway detection on odd VM\n// after\nDefaultDockerClientConfig.createDefaultConfigBuilder()\n    .withDockerHost(\"tcp://192.168.99.100:2376\")\n    .build();","handlingStrategy":"fallback","validationCode":"String host = System.getenv(\"DOCKER_HOST\");\nif (host == null || host.isEmpty()) { /* set DOCKER_HOST so gateway detection is skipped */ }","typeGuard":null,"tryCatchPattern":"try {\n    container.start();\n} catch (IllegalStateException e) {\n    log.warn(\"Gateway IP detection failed; check DOCKER_HOST/network setup\", e);\n}","preventionTips":["Set DOCKER_HOST explicitly in CI and VM-based Docker setups.","Avoid legacy docker-machine/Toolbox environments.","Keep Testcontainers and docker-java versions current."],"tags":["docker","network","gateway","docker-host"],"backgroundTag":"network-request-failed","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}