testcontainers/testcontainers-java · error · IllegalStateException

Could not find a default docker-machine instance

Error message

Could not find a default docker-machine instance

What it means

Thrown by the deprecated getTestHostIpAddress: docker-machine is installed, but querying it returns no default machine (empty Optional), so Testcontainers cannot determine the host IP and raises an IllegalStateException. The missing input is a default docker-machine instance.

Solutions

  1. Create or start a docker-machine default instance (docker-machine create/start default)
  2. Run against a locally installed Docker daemon instead of docker-machine
  3. Avoid the deprecated getTestHostIpAddress and use container networking
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at core/src/main/java/org/testcontainers/containers/GenericContainer.java:1322 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12). Data as JSON: /api/errors/7b19123713473448. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/testcontainers/containers/GenericContainer.java:1322

    public String getDockerImageName() {
        try {
            return image.get();
        } catch (Exception e) {
            throw new ContainerFetchException("Can't get Docker image: " + image, e);
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    @Deprecated
    public String getTestHostIpAddress() {
        if (DockerMachineClient.instance().isInstalled()) {
            try {
                Optional<String> defaultMachine = DockerMachineClient.instance().getDefaultMachine();
                if (!defaultMachine.isPresent()) {
                    throw new IllegalStateException("Could not find a default docker-machine instance");
                }

                String sshConnectionString = CommandLine
                    .runShellCommand("docker-machine", "ssh", defaultMachine.get(), "echo $SSH_CONNECTION")
                    .trim();
                if (Strings.isNullOrEmpty(sshConnectionString)) {
                    throw new IllegalStateException(
                        "Could not obtain SSH_CONNECTION environment variable for docker machine " +
                        defaultMachine.get()
                    );
                }

                String[] sshConnectionParts = sshConnectionString.split("\\s");
                if (sshConnectionParts.length != 4) {
                    throw new IllegalStateException(
                        "Unexpected pattern for SSH_CONNECTION for docker machine - expected 'IP PORT IP PORT' pattern but found '" +
                        sshConnectionString +
                        "'"

View on GitHub (pinned to 8e549514e3)