{"record":{"id":"5749da647dbbe341","repo":"testcontainers/testcontainers-java","slug":"this-container-s-image-does-not-have-a-healthcheck-declared","errorCode":null,"errorMessage":"This container's image does not have a healthcheck declared, so health cannot be determined. Either amend the image or use another approach to determine whether containers are healthy.","messagePattern":"This container's image does not have a healthcheck declared, so health cannot be determined\\. Either amend the image or use another approach to determine whether containers are healthy\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/testcontainers/containers/ContainerState.java","lineNumber":111,"sourceCode":"            return \"created\".equalsIgnoreCase(status) || isRunning();\n        } catch (DockerException e) {\n            return false;\n        }\n    }\n\n    /**\n     * @return has the container health state 'healthy'?\n     */\n    default boolean isHealthy() {\n        if (getContainerId() == null) {\n            return false;\n        }\n\n        try {\n            InspectContainerResponse inspectContainerResponse = getCurrentContainerInfo();\n            HealthState health = inspectContainerResponse.getState().getHealth();\n            if (health == null) {\n                throw new RuntimeException(\n                    \"This container's image does not have a healthcheck declared, so health cannot be determined. Either amend the image or use another approach to determine whether containers are healthy.\"\n                );\n            }\n\n            return STATE_HEALTHY.equals(health.getStatus());\n        } catch (DockerException e) {\n            return false;\n        }\n    }\n\n    /**\n     * Inspects the container and returns up-to-date inspection response.\n     *\n     * @return up-to-date container inspect response\n     * @see #getContainerInfo()\n     */\n    default InspectContainerResponse getCurrentContainerInfo() {\n        return getDockerClient().inspectContainerCmd(getContainerId()).exec();","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/containers/ContainerState.java#L93-L129","documentation":"ContainerState.isHealthy() inspects the container's Docker health state; if the image declares no HEALTHCHECK the Docker API returns no health object and the method throws a RuntimeException, since healthiness is undefined without a healthcheck.","triggerScenarios":"Calling isHealthy(), or using Wait.forHealthcheck() / waitingFor(HealthCheckWaitStrategy), on a container whose image has no HEALTHCHECK instruction.","commonSituations":"Using Healthcheck-based wait strategies with community images that lack HEALTHCHECK; expecting Docker's health status for custom Dockerfiles without a HEALTHCHECK line.","solutions":["Add a HEALTHCHECK instruction to the image Dockerfile and rebuild","Use a different wait strategy, e.g. Wait.forListeningPort() or Wait.forHttp(\"/health\") instead of forHealthcheck()","If the base image can't be changed, wrap the container in a new image that adds the HEALTHCHECK"],"exampleFix":"// before\nnew GenericContainer<>(\"nginx:1.25\").waitingFor(Wait.forHealthcheck());\n// after\nnew GenericContainer<>(\"nginx:1.25\").waitingFor(Wait.forHttp(\"/\").forStatusCode(200));","handlingStrategy":"fallback","validationCode":"boolean hasHealthcheck = DockerClientFactory.instance().client().inspectImageCmd(image).exec().getConfig().getHealthcheck() != null; if (!hasHealthcheck) useFallbackWaitStrategy();","typeGuard":null,"tryCatchPattern":"try { return container.isHealthy(); } catch (RuntimeException e) { if (e.getMessage().contains(\"healthcheck declared\")) { return fallbackReadinessCheck(container); } throw e; }","preventionTips":["Inspect image config for HEALTHCHECK before choosing Wait.forHealthcheck()","Prefer Wait.forHttp/forListeningPort for images without healthchecks","Document which custom images carry a HEALTHCHECK"],"tags":["healthcheck","docker-image","wait-strategy","container"],"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"}