Skip to content

Fix DockerComposeContainer to support compose files from different directories#11925

Open
snehal242005 wants to merge 1 commit into
testcontainers:mainfrom
snehal242005:fix/1863-docker-compose-multiple-locations
Open

Fix DockerComposeContainer to support compose files from different directories#11925
snehal242005 wants to merge 1 commit into
testcontainers:mainfrom
snehal242005:fix/1863-docker-compose-multiple-locations

Conversation

@snehal242005

Copy link
Copy Markdown

Closes #1863

What does this PR do?

DockerComposeContainer (containerized mode) previously determined the working
directory / root for docker-compose using only the first compose file's parent
directory. When additional compose files lived in a different directory, that
directory was never copied into the container, causing a FileNotFoundError.

This PR:

  • Adds PathUtils.findCommonParent(List<File>), which computes the closest
    common ancestor directory of all provided compose files.
  • Updates ContainerisedDockerCompose to use this common parent as the root
    directory that gets copied into the container, instead of just the first
    file's directory — ensuring every provided compose file is reachable.
  • Fixes a related bug where, when withCopyFilesInContainer was used, only
    the base compose file was copied into the container individually — other
    compose files were silently dropped even in the same-directory case. All
    compose files are now copied correctly.
  • Behavior is unchanged when all compose files share one directory (the
    common case) — findCommonParent reduces to that same directory.

How to test?

  1. Create two docker-compose files in different directories, e.g.:
    • first/directory/docker-compose.yml
    • first/docker-compose.override.yml
  2. Construct a DockerComposeContainer with both files
  3. Previously: FileNotFoundError. Now: both files resolve and the container
    starts correctly.

Tests

Added PathUtilsTest.java covering:

  • Single file → its own directory
  • Files in the same directory → that directory
  • The issue's exact scenario (files in different directories) → correct
    common parent
  • Order independence
  • Sibling directories → shared parent

All 5 tests pass (./gradlew :testcontainers:test --tests PathUtilsTest).

Mandatory checks

  • Tests created for changes
  • Manually verified logic against the exact scenario from the issue
  • No changes needed to documentation

@snehal242005 snehal242005 requested a review from a team as a code owner July 13, 2026 04:54
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.

docker-compose files from two different locations

1 participant