{"record":{"id":"45256f84a5b3e31a","repo":"testcontainers/testcontainers-java","slug":"timed-out-waiting-for-container-to-execute-s-successfully","errorCode":null,"errorMessage":"Timed out waiting for container to execute `%s` successfully.","messagePattern":"Timed out waiting for container to execute `(.+?)` successfully\\.","errorType":"exception","errorClass":"ContainerLaunchException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/testcontainers/containers/wait/strategy/ShellStrategy.java","lineNumber":27,"sourceCode":"public class ShellStrategy extends AbstractWaitStrategy {\n\n    private String command;\n\n    public ShellStrategy withCommand(String command) {\n        this.command = command;\n        return this;\n    }\n\n    @Override\n    protected void waitUntilReady() {\n        try {\n            Unreliables.retryUntilTrue(\n                (int) startupTimeout.getSeconds(),\n                TimeUnit.SECONDS,\n                () -> waitStrategyTarget.execInContainer(\"/bin/sh\", \"-c\", this.command).getExitCode() == 0\n            );\n        } catch (TimeoutException e) {\n            throw new ContainerLaunchException(\n                \"Timed out waiting for container to execute `\" + this.command + \"` successfully.\"\n            );\n        }\n    }\n}\n","sourceCodeStart":9,"sourceCodeEnd":33,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/containers/wait/strategy/ShellStrategy.java#L9-L33","documentation":"ShellStrategy waits by repeatedly executing /bin/sh -c <command> inside the container until it exits with code 0. If the command still returns a non-zero exit code when the startup timeout expires, a TimeoutException is wrapped in this ContainerLaunchException naming the command.","triggerScenarios":"Container startup configured with new ShellStrategy().withCommand(\"psql -h host -U user ...\") (often inside .waitingFor(...)) while the probe command keeps failing — target service not up, wrong credentials/host, or the command itself is buggy.","commonSituations":"Port-check one-liners (e.g. 'wget --spider ...') failing because the inner service is not ready or wget/curl isn't installed; wrong DB user/password in the probe; timeout too short for the dependent service to boot.","solutions":["Run the command manually: container.execInContainer(\"/bin/sh\",\"-c\",cmd) and inspect output/exit code","Fix the probe command (correct host, credentials, and an available tool like nc/curl)","Increase the timeout: strategy.withStartupTimeout(Duration.ofMinutes(2))","Consider a HttpWaitStrategy/LogMessageWaitStrategy if a probe command is awkward"],"exampleFix":"// before\nnew ShellStrategy().withCommand(\"curl -f http://localhost:8080/health\").withStartupTimeout(Duration.ofSeconds(20));\n// after\nnew ShellStrategy().withCommand(\"wget -qO- http://localhost:8080/health || exit 1\").withStartupTimeout(Duration.ofMinutes(2));","handlingStrategy":"retry","validationCode":"// Probe the command once before relying on it for the wait strategy\nExecResult r = container.execInContainer(\"/bin/sh\", \"-c\", probeCommand);\nif (r.getExitCode() != 0) {\n    throw new IllegalStateException(\"Probe failed (exit \" + r.getExitCode() + \"): \" + r.getStderr());\n}","typeGuard":null,"tryCatchPattern":"try {\n    container.waitingFor(new ShellStrategy().withCommand(probeCommand)).start();\n} catch (ContainerLaunchException e) {\n    if (e.getMessage().startsWith(\"Timed out waiting for container to execute\")) {\n        System.err.println(container.execInContainer(\"/bin/sh\", \"-c\", probeCommand).getStderr());\n    }\n    throw e;\n}","preventionTips":["Test the probe command manually inside the container image","Ensure the probe tool (curl/wget/nc) is installed in the image","Use correct host/credentials in the probe and a generous startup timeout"],"tags":["timeout","shell","exec","wait-strategy","testcontainers"],"backgroundTag":"wait-strategy-timeout","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"}