diff --git a/core/src/main/java/org/testcontainers/containers/ParsedDockerComposeFile.java b/core/src/main/java/org/testcontainers/containers/ParsedDockerComposeFile.java index d797a86bfbf..3db14190860 100644 --- a/core/src/main/java/org/testcontainers/containers/ParsedDockerComposeFile.java +++ b/core/src/main/java/org/testcontainers/containers/ParsedDockerComposeFile.java @@ -131,12 +131,11 @@ private void parseAndValidate() { private void validateNoContainerNameSpecified(String serviceName, Map serviceDefinitionMap) { if (serviceDefinitionMap.containsKey("container_name")) { - throw new IllegalStateException( - String.format( - "Compose file %s has 'container_name' property set for service '%s' but this property is not supported by Testcontainers, consider removing it", - composeFileName, - serviceName - ) + log.warn( + "Compose file {} has 'container_name' property set for service '{}'. " + + "This property is not supported by Testcontainers and will be ignored.", + composeFileName, + serviceName ); } } diff --git a/core/src/test/java/org/testcontainers/containers/ParsedDockerComposeFileValidationTest.java b/core/src/test/java/org/testcontainers/containers/ParsedDockerComposeFileValidationTest.java index 36126df6a38..f3e9a219009 100644 --- a/core/src/test/java/org/testcontainers/containers/ParsedDockerComposeFileValidationTest.java +++ b/core/src/test/java/org/testcontainers/containers/ParsedDockerComposeFileValidationTest.java @@ -22,26 +22,26 @@ class ParsedDockerComposeFileValidationTest { public Path temporaryFolder; @Test - void shouldValidate() { + void shouldIgnoreContainerNameV1() { File file = new File("src/test/resources/docker-compose-container-name-v1.yml"); - assertThatThrownBy(() -> { - new ParsedDockerComposeFile(file); - }) - .hasMessageContaining(file.getAbsolutePath()) - .hasMessageContaining("'container_name' property set for service 'redis'"); + // container_name should be ignored (with a warning log) instead of throwing an exception + assertThatNoException().isThrownBy(() -> new ParsedDockerComposeFile(file)); } @Test - void shouldRejectContainerNameV1() { - assertThatThrownBy(() -> { - new ParsedDockerComposeFile(ImmutableMap.of("redis", ImmutableMap.of("container_name", "redis"))); - }) - .hasMessageContaining("'container_name' property set for service 'redis'"); + void shouldIgnoreContainerNameInMapV1() { + // container_name should be ignored (with a warning log) instead of throwing an exception + assertThatNoException() + .isThrownBy(() -> + new ParsedDockerComposeFile(ImmutableMap.of("redis", ImmutableMap.of("container_name", "redis"))) + ); } @Test - void shouldRejectContainerNameV2() { - assertThatThrownBy(() -> { + void shouldIgnoreContainerNameV2() { + // container_name should be ignored (with a warning log) instead of throwing an exception + assertThatNoException() + .isThrownBy(() -> new ParsedDockerComposeFile( ImmutableMap.of( "version", @@ -49,9 +49,8 @@ void shouldRejectContainerNameV2() { "services", ImmutableMap.of("redis", ImmutableMap.of("container_name", "redis")) ) - ); - }) - .hasMessageContaining("'container_name' property set for service 'redis'"); + ) + ); } @Test