{"record":{"id":"12e57c0773feb188","repo":"testcontainers/testcontainers-java","slug":"services-named-do-not-exist-but-wait-conditions-have-been","errorCode":null,"errorMessage":"Services named {} {} do not exist, but wait conditions have been defined for them. This might mean that you misspelled the service name when defining the wait condition.","messagePattern":"Services named (.+?) (.+?) do not exist, but wait conditions have been defined for them\\. This might mean that you misspelled the service name when defining the wait condition\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/testcontainers/containers/ComposeDelegate.java","lineNumber":174,"sourceCode":"        }\n\n        if (!Strings.isNullOrEmpty(serviceNameArgs)) {\n            command += \" \" + serviceNameArgs;\n        }\n\n        // Run the docker compose container, which starts up the services\n        runWithCompose(localCompose, command, env, fileCopyInclusions);\n    }\n\n    void waitUntilServiceStarted(boolean tailChildContainers) {\n        listChildContainers().forEach(container -> createServiceInstance(container, tailChildContainers));\n\n        Set<String> servicesToWaitFor = waitStrategyMap.keySet();\n        Set<String> instantiatedServices = serviceInstanceMap.keySet();\n        Sets.SetView<String> missingServiceInstances = Sets.difference(servicesToWaitFor, instantiatedServices);\n\n        if (!missingServiceInstances.isEmpty()) {\n            throw new IllegalStateException(\n                \"Services named \" +\n                missingServiceInstances +\n                \" \" +\n                \"do not exist, but wait conditions have been defined \" +\n                \"for them. This might mean that you misspelled \" +\n                \"the service name when defining the wait condition.\"\n            );\n        }\n\n        serviceInstanceMap.forEach(this::waitUntilServiceStarted);\n    }\n\n    private void createServiceInstance(Container container, boolean tailChildContainers) {\n        String serviceName = getServiceNameFromContainer(container);\n        final ComposeServiceWaitStrategyTarget containerInstance = new ComposeServiceWaitStrategyTarget(\n            dockerClient,\n            container,\n            ambassadorContainer,","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/containers/ComposeDelegate.java#L156-L192","documentation":"When a Compose stack starts, ComposeDelegate.waitUntilServiceStarted verifies that every service with a registered wait strategy actually exists among the containers the stack instantiated. If waitStrategyMap has service names that are absent from serviceInstanceMap, it throws IllegalStateException listing the missing services.","triggerScenarios":"Calling withExposedService(\"servicename\", port) or waitingFor(...) on a DockerComposeContainer with a service name that does not match any service defined in the docker-compose file (names are case-sensitive; scaling can also affect instance naming).","commonSituations":"Typo or wrong case in the service name (e.g. 'DB' vs 'db'); wait condition referencing a service only started by a different compose profile/override file; service renamed in docker-compose.yml after tests were written.","solutions":["Compare the service name(s) in the exception with the service keys in your docker-compose file","Fix the name passed to withExposedService/waitingFor to exactly match the compose service (including case)","Remove wait conditions for services that the compose file does not define","If using profiles/overrides, ensure the service is actually started in the merged configuration"],"exampleFix":"// before\n.compose(\"docker-compose.yml\")\n.withExposedService(\"databse_1\", 5432, Wait.defaultWaitStrategy())\n// after\n.compose(\"docker-compose.yml\")\n.withExposedService(\"database_1\", 5432, Wait.defaultWaitStrategy())","handlingStrategy":"validation","validationCode":"Set<String> composeServices = parseServiceNamesFromComposeYaml(Paths.get(\"docker-compose.yml\")); waitStrategyNames.forEach(n -> { if (!composeServices.contains(n)) throw new IllegalArgumentException(\"Unknown compose service: \" + n); });","typeGuard":null,"tryCatchPattern":"try { composeContainer.start(); } catch (IllegalStateException e) { if (e.getMessage().contains(\"do not exist, but wait conditions\")) { log.error(\"Fix withExposedService/waitingFor names: {}\", e.getMessage()); } throw e; }","preventionTips":["Keep service names in one constants class shared between compose file and tests","Remember instance suffix naming (e.g. 'db_1') and case sensitivity","Regenerate wait conditions whenever the compose file changes"],"tags":["docker-compose","configuration","service-name","wait-strategy"],"backgroundTag":"resource-not-found","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"}