Skip to content

Conversation

@ranjitm2001
Copy link

Summary

Fixes #2472

Changes

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.

Implementation Details

  • ParsedDockerComposeFile.java: Changed validateNoContainerNameSpecified() to log a warning instead of throwing IllegalStateException
  • ParsedDockerComposeFileValidationTest.java: Updated tests to verify that container_name is now ignored rather than rejected

Testing

All existing tests pass, and the updated tests verify the new behavior:

  • shouldIgnoreContainerNameV1() - Tests file-based compose with container_name
  • shouldIgnoreContainerNameInMapV1() - Tests v1 format map with container_name
  • shouldIgnoreContainerNameV2() - Tests v2 format with container_name

Motivation

As discussed in #2472, many users want to reuse their production docker-compose files for testing. The container_name property is valid Docker Compose syntax and should not cause Testcontainers to fail. Instead, it should be gracefully ignored with a warning.

…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
@ranjitm2001 ranjitm2001 requested a review from a team as a code owner December 29, 2025 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support container_name in docker-compose file

1 participant