{"record":{"id":"a058e57644a01b0d","repo":"testcontainers/testcontainers-java","slug":"compose-file-composefilename-has-container-name-property-set","errorCode":null,"errorMessage":"Compose file ${composeFileName} has 'container_name' property set for service '${serviceName}' but this property is not supported by Testcontainers, consider removing it","messagePattern":"Compose file (.+?) has 'container_name' property set for service '(.+?)' but this property is not supported by Testcontainers, consider removing it","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/testcontainers/containers/ParsedDockerComposeFile.java","lineNumber":134,"sourceCode":"                    \"Compose file {} has an unknown format: service '{}' is not Map\",\n                    composeFileName,\n                    serviceName\n                );\n                break;\n            }\n\n            @SuppressWarnings(\"unchecked\")\n            final Map<String, ?> serviceDefinitionMap = (Map<String, ?>) serviceDefinition;\n\n            validateNoContainerNameSpecified(serviceName, serviceDefinitionMap);\n            findServiceImageName(serviceName, serviceDefinitionMap);\n            findImageNamesInDockerfile(serviceName, serviceDefinitionMap);\n        }\n    }\n\n    private void validateNoContainerNameSpecified(String serviceName, Map<String, ?> serviceDefinitionMap) {\n        if (serviceDefinitionMap.containsKey(\"container_name\")) {\n            throw new IllegalStateException(\n                String.format(\n                    \"Compose file %s has 'container_name' property set for service '%s' but this property is not supported by Testcontainers, consider removing it\",\n                    composeFileName,\n                    serviceName\n                )\n            );\n        }\n    }\n\n    private void findServiceImageName(String serviceName, Map<String, ?> serviceDefinitionMap) {\n        Object result = serviceDefinitionMap.get(\"image\");\n        if (result instanceof String) {\n            final String imageName = (String) result;\n            log.debug(\"Resolved dependency image for Docker Compose in {}: {}\", composeFileName, imageName);\n            serviceNameToImageNames.put(serviceName, Sets.newHashSet(imageName));\n        }\n    }\n","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/containers/ParsedDockerComposeFile.java#L116-L152","documentation":"Testcontainers requires unique, dynamically generated container names, so a compose service declaring `container_name` breaks container reuse and network identity. parseAndValidate() rejects any service definition containing that key with an IllegalStateException telling the developer to remove it.","triggerScenarios":"A compose file passed to DockerComposeContainer/ParsedDockerComposeFile contains, under any service, the key `container_name: <name>`. The check runs for every service during parseAndValidate().","commonSituations":"Reusing a compose file written for plain `docker-compose up` where container_name was set for networking or log correlation; copying examples from the internet that set container_name.","solutions":["Remove the `container_name` key from each service in the compose file.","Reference services by service name instead of container name (Testcontainers registers network aliases per service).","Keep a separate trimmed compose file for tests if the same file must serve local runs."],"exampleFix":"# before\nservices:\n  db:\n    image: postgres:16\n    container_name: my-postgres\n# after\nservices:\n  db:\n    image: postgres:16","handlingStrategy":"validation","validationCode":"String yaml = Files.readString(file.toPath());\nif (yaml.contains(\"container_name:\")) throw new IllegalStateException(\"remove container_name before using with Testcontainers\");","typeGuard":null,"tryCatchPattern":"try { new ParsedDockerComposeFile(file); } catch (IllegalStateException e) { throw new ConfigurationException(\"Compose file invalid for Testcontainers: \" + e.getMessage(), e); }","preventionTips":["Strip container_name from any compose file used in tests.","Address services by service name, never by container name.","Maintain a dedicated test compose file rather than reusing runtime ones."],"tags":["compose-file","validation","container-name"],"backgroundTag":"unsupported-config-value","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"}