{"record":{"id":"098f66e00bf127a5","repo":"testcontainers/testcontainers-java","slug":"no-exposed-ports-or-mapped-ports-cannot-wait-for-status","errorCode":null,"errorMessage":"{}: No exposed ports or mapped ports - cannot wait for status","messagePattern":"(.+?): No exposed ports or mapped ports - cannot wait for status","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/src/main/java/org/testcontainers/containers/wait/strategy/HttpWaitStrategy.java","lineNumber":217,"sourceCode":"     * Waits for the response to pass the given predicate\n     * @param responsePredicate The predicate to test the response against\n     * @return this\n     */\n    public HttpWaitStrategy forResponsePredicate(Predicate<String> responsePredicate) {\n        this.responsePredicate = responsePredicate;\n        return this;\n    }\n\n    @Override\n    protected void waitUntilReady() {\n        final String containerName = waitStrategyTarget.getContainerInfo().getName();\n\n        final Integer livenessCheckPort = livenessPort\n            .map(waitStrategyTarget::getMappedPort)\n            .orElseGet(() -> {\n                final Set<Integer> livenessCheckPorts = getLivenessCheckPorts();\n                if (livenessCheckPorts == null || livenessCheckPorts.isEmpty()) {\n                    log.warn(\"{}: No exposed ports or mapped ports - cannot wait for status\", containerName);\n                    return -1;\n                }\n                return livenessCheckPorts.iterator().next();\n            });\n\n        if (null == livenessCheckPort || -1 == livenessCheckPort) {\n            return;\n        }\n        final URI rawUri = buildLivenessUri(livenessCheckPort);\n        final String uri = rawUri.toString();\n\n        try {\n            // Un-map the port for logging\n            int originalPort = waitStrategyTarget\n                .getExposedPorts()\n                .stream()\n                .filter(exposedPort -> rawUri.getPort() == waitStrategyTarget.getMappedPort(exposedPort))\n                .findFirst()","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/containers/wait/strategy/HttpWaitStrategy.java#L199-L235","documentation":"HttpWaitStrategy.waitUntilReady() needs a port to issue its HTTP liveness request. When no liveness port was configured and the container exposes no ports (getLivenessCheckPorts() empty), it logs this warning and uses -1, which aborts the wait immediately, producing a ContainerLaunchException / wait failure instead of an HTTP check.","triggerScenarios":"Using HttpWaitStrategy (e.g. Wait.forHttp(\"/health\")) on a container that calls neither .exposedPorts(...)/addExposedPort nor .withExposedPorts(...), and without HttpWaitStrategy.withLivenessPassingPorts()/livenessPort set — i.e. no exposed or mapped ports exist.","commonSituations":"Forgetting to call addExposedPorts() on GenericContainer while attaching an HTTP wait strategy; containers whose ports are declared only inside the image but the image has no EXPOSE; custom WaitStrategyTarget implementations not reporting ports.","solutions":["Expose the port the HTTP check should hit: container.addExposedPorts(8080) (or withExposedPorts in DockerComposeContainer rules).","If the check must use a different port than the response port, set it explicitly with HttpWaitStrategy.forPort(8080).","Ensure the image declares EXPOSE for the port so getLivenessCheckPorts() returns it.","If using a custom WaitStrategyTarget, make getExposedPorts/getMappedPort return real values."],"exampleFix":"// before\nGenericContainer<?> c = new GenericContainer<>(\"myapp:latest\")\n    .waitingFor(Wait.forHttp(\"/health\").forStatusCode(200)); // no ports exposed\n// after\nGenericContainer<?> c = new GenericContainer<>(\"myapp:latest\")\n    .withExposedPorts(8080)\n    .waitingFor(Wait.forHttp(\"/health\").forStatusCode(200).forPort(8080));","handlingStrategy":"validation","validationCode":"if (container.getExposedPorts().isEmpty()) {\n    throw new IllegalStateException(\"HttpWaitStrategy requires at least one exposed port; call addExposedPorts(...) first\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    container.start();\n} catch (ContainerLaunchException e) {\n    if (e.getMessage().contains(\"No exposed ports\")) { /* fix port exposure */ }\n}","preventionTips":["Always call withExposedPorts/addExposedPorts before attaching HTTP wait strategies.","Ensure the image has EXPOSE directives.","Specify .forPort(...) explicitly on HttpWaitStrategy."],"tags":["wait-strategy","http","ports","configuration"],"backgroundTag":"missing-required-config","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"}