Ignore container_name in docker-compose files instead of throwing exception#11376
Conversation
…eption Fixes testcontainers#2472 Previously, Testcontainers would throw an IllegalStateException when parsing a docker-compose file that contained the 'container_name' property. This prevented users from reusing their production docker-compose files without modification. This change modifies the behavior to log a warning instead of throwing an exception, allowing users to use docker-compose files with container_name properties. The container_name is simply ignored since Testcontainers manages container naming internally. Changes: - ParsedDockerComposeFile: Changed validateNoContainerNameSpecified() to log a warning instead of throwing IllegalStateException - ParsedDockerComposeFileValidationTest: Updated tests to verify that container_name is now ignored rather than rejected
|
I tested your branch because I was running into a similar problem. With this change, the What your change does allow is using docker compose override files with |
|
Docker compose support it was supposed to help with transition from compose files to Testcontainers' modules. So, this is an opinionated implementation to support Compose in Testcontainers. |
Summary
Fixes #2472
Changes
Previously, Testcontainers would throw an
IllegalStateExceptionwhen parsing a docker-compose file that contained thecontainer_nameproperty. This prevented users from reusing their production docker-compose files without modification.This change modifies the behavior to log a warning instead of throwing an exception, allowing users to use docker-compose files with
container_nameproperties. Thecontainer_nameis simply ignored since Testcontainers manages container naming internally.Implementation Details
validateNoContainerNameSpecified()to log a warning instead of throwingIllegalStateExceptioncontainer_nameis now ignored rather than rejectedTesting
All existing tests pass, and the updated tests verify the new behavior:
shouldIgnoreContainerNameV1()- Tests file-based compose with container_nameshouldIgnoreContainerNameInMapV1()- Tests v1 format map with container_nameshouldIgnoreContainerNameV2()- Tests v2 format with container_nameMotivation
As discussed in #2472, many users want to reuse their production docker-compose files for testing. The
container_nameproperty is valid Docker Compose syntax and should not cause Testcontainers to fail. Instead, it should be gracefully ignored with a warning.