{"record":{"id":"3f58a4d64ce16851","repo":"testcontainers/testcontainers-java","slug":"gettesthostipaddress-is-only-implemented-for-docker-machine","errorCode":null,"errorMessage":"getTestHostIpAddress() is only implemented for docker-machine right now","messagePattern":"getTestHostIpAddress\\(\\) is only implemented for docker-machine right now","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/testcontainers/containers/GenericContainer.java","lineNumber":1349,"sourceCode":"                        defaultMachine.get()\n                    );\n                }\n\n                String[] sshConnectionParts = sshConnectionString.split(\"\\\\s\");\n                if (sshConnectionParts.length != 4) {\n                    throw new IllegalStateException(\n                        \"Unexpected pattern for SSH_CONNECTION for docker machine - expected 'IP PORT IP PORT' pattern but found '\" +\n                        sshConnectionString +\n                        \"'\"\n                    );\n                }\n\n                return sshConnectionParts[0];\n            } catch (Exception e) {\n                throw new RuntimeException(e);\n            }\n        } else {\n            throw new UnsupportedOperationException(\n                \"getTestHostIpAddress() is only implemented for docker-machine right now\"\n            );\n        }\n    }\n\n    /**\n     * {@inheritDoc}\n     */\n    @Override\n    public SELF withLogConsumer(Consumer<OutputFrame> consumer) {\n        this.logConsumers.add(consumer);\n\n        return self();\n    }\n\n    /**\n     * {@inheritDoc}\n     */","sourceCodeStart":1331,"sourceCodeEnd":1367,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/containers/GenericContainer.java#L1331-L1367","documentation":"Thrown by GenericContainer.getTestHostIpAddress() as an UnsupportedOperationException when the container is NOT running against a docker-machine VM. The only implemented strategy for resolving the test host IP at this point in the code is via docker-machine's SSH_CONNECTION; all other environments fall through to this branch. It signals an unimplemented feature for the current Docker environment, not a broken configuration per se.","triggerScenarios":"Calling getTestHostIpAddress() when no DOCKER_MACHINE_NAME/default machine is detected — e.g. plain Linux Docker, Docker for Desktop (Mac/Windows), or remote DOCKER_HOST environments where a different host-IP detection strategy (like TestContainers' normal internal per-container resolution) should be used instead.","commonSituations":"Developers calling getTestHostIpAddress() directly to connect test clients to a container on Docker for Desktop or Linux; copying docker-machine-era test code into a modern Docker setup; older TestContainers versions before richer host-IP detection was implemented.","solutions":["Do not call getTestHostIpAddress(); use container.getHost() (and getMappedPort) to obtain the address TestContainers already resolves for the environment.","Upgrade TestContainers — modern versions implement host IP detection for Docker for Desktop and other environments.","If you truly need the docker-machine flow, run against a docker-machine VM with DOCKER_MACHINE_NAME set.","Compute the host IP manually from the docker bridge network (e.g. `ip route` / gateway IP) only as a last resort."],"exampleFix":"// before\nString host = container.getTestHostIpAddress(); // UnsupportedOperationException\n\n// after\nString host = container.getHost();\nInteger port = container.getMappedPort(8080);","handlingStrategy":"validation","validationCode":"// Only call getTestHostIpAddress() when actually on docker-machine\nif (System.getenv(\"DOCKER_MACHINE_NAME\") == null) {\n    // use the portable API instead\n    String host = container.getHost();\n}","typeGuard":"boolean isDockerMachineEnv() {\n    return System.getenv(\"DOCKER_MACHINE_NAME\") != null;\n}","tryCatchPattern":"try {\n    String ip = container.getTestHostIpAddress();\n} catch (UnsupportedOperationException e) {\n    String host = container.getHost(); // portable fallback\n}","preventionTips":["Use container.getHost()/getMappedPort() instead of getTestHostIpAddress() in portable tests.","Only rely on getTestHostIpAddress() when DOCKER_MACHINE_NAME is set.","Keep TestContainers up to date for broader host-IP support.","Abstract host resolution behind a helper that switches on environment."],"tags":["docker","unsupported-operation","host-ip"],"backgroundTag":"unsupported-operation","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"}