{"record":{"id":"cda40dc8ce8b45eb","repo":"testcontainers/testcontainers-java","slug":"testcontainers-may-not-be-able-to-clean-up-networks-spawned","errorCode":null,"errorMessage":"Testcontainers may not be able to clean up networks spawned using Docker Compose v2.0 files. Please see https://github.com/testcontainers/moby-ryuk/issues/2, and specify 'version: \"2.1\"' or higher in {}","messagePattern":"Testcontainers may not be able to clean up networks spawned using Docker Compose v2\\.0 files\\. Please see https://github\\.com/testcontainers/moby-ryuk/issues/2, and specify 'version: \"2\\.1\"' or higher in (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/src/main/java/org/testcontainers/containers/ParsedDockerComposeFile.java","lineNumber":82,"sourceCode":"        }\n        this.composeFileName = composeFile.getAbsolutePath();\n        this.composeFile = composeFile;\n        parseAndValidate();\n    }\n\n    @VisibleForTesting\n    ParsedDockerComposeFile(Map<String, Object> testContent) {\n        this.composeFileContent = testContent;\n        this.composeFileName = \"\";\n        this.composeFile = new File(\".\");\n\n        parseAndValidate();\n    }\n\n    private void parseAndValidate() {\n        final Map<String, ?> servicesMap;\n        if (composeFileContent.containsKey(\"version\") && \"2.0\".equals(composeFileContent.get(\"version\"))) {\n            log.warn(\n                \"Testcontainers may not be able to clean up networks spawned using Docker Compose v2.0 files. \" +\n                \"Please see https://github.com/testcontainers/moby-ryuk/issues/2, and specify 'version: \\\"2.1\\\"' or \" +\n                \"higher in {}\",\n                composeFileName\n            );\n        }\n\n        if (composeFileContent.containsKey(\"services\")) {\n            final Object servicesElement = composeFileContent.get(\"services\");\n            if (servicesElement == null) {\n                log.debug(\n                    \"Compose file {} has an unknown format: 'version' is set but 'services' is not defined\",\n                    composeFileName\n                );\n                return;\n            }\n            if (!(servicesElement instanceof Map)) {\n                log.debug(\"Compose file {} has an unknown format: 'services' is not Map\", composeFileName);","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/containers/ParsedDockerComposeFile.java#L64-L100","documentation":"ParsedDockerComposeFile.parseAndValidate() warns when a compose file declares `version: \"2.0\"`. Compose 2.0 files lack the network metadata Testcontainers' resource reaper (moby-ryuk) needs, so networks spawned from such files may be leaked and never cleaned up. The warning points users to pin version 2.1 or higher.","triggerScenarios":"Parsing (constructing ParsedDockerComposeFile, which calls parseAndValidate) a docker-compose file whose YAML top-level `version` key equals the string \"2.0\".","commonSituations":"Old projects with legacy compose files pinned to \"2.0\" used with DockerComposeContainer; copies of very old example compose files; files copied from tutorials predating 2.1.","solutions":["Edit the compose file to declare version: \"2.1\" or higher (or omit `version` entirely for Compose v2 spec files).","Verify the container definitions still work under the newer compose file format.","Re-run the tests and confirm Ryuk can clean up the spawned networks."],"exampleFix":"# before\nversion: \"2.0\"\nservices:\n  db:\n    image: postgres:13\n# after\nversion: \"2.4\"\nservices:\n  db:\n    image: postgres:13","handlingStrategy":"validation","validationCode":"final String version = (String) yaml.get(\"version\");\nif (\"2.0\".equals(version)) {\n    throw new IllegalStateException(\"Compose file uses deprecated 2.0; bump to 2.1+ for Ryuk network cleanup\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use version \"2.4\" (or no version key) in all compose files used by tests.","Add a CI lint that rejects compose files with version 2.0.","Watch for this warning on startup and treat it as a config bug."],"tags":["docker-compose","compose-file","resource-cleanup","version"],"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"}