Ignore container_name in docker-compose files instead of throwing exception #11376
+20
−22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.