Skip to content

feat(core): DockerCompose: support list of env_files #847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions core/testcontainers/compose/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class DockerCompose:
Wait for the services to be healthy
(as per healthcheck definitions in the docker compose configuration)
env_file:
Path to an '.env' file containing environment variables
Path(s) to an '.env' file containing environment variables
to pass to docker compose.
services:
The list of services to use from this DockerCompose.
Expand Down Expand Up @@ -210,7 +210,7 @@ class DockerCompose:
build: bool = False
wait: bool = True
keep_volumes: bool = False
env_file: Optional[str] = None
env_file: Optional[Union[str, list[str]]] = None
services: Optional[list[str]] = None
docker_command_path: Optional[str] = None
profiles: Optional[list[str]] = None
Expand All @@ -219,6 +219,8 @@ class DockerCompose:
def __post_init__(self) -> None:
if isinstance(self.compose_file_name, str):
self.compose_file_name = [self.compose_file_name]
if isinstance(self.env_file, str):
self.env_file = [self.env_file]

def __enter__(self) -> "DockerCompose":
self.start()
Expand Down Expand Up @@ -247,7 +249,8 @@ def compose_command_property(self) -> list[str]:
if self.profiles:
docker_compose_cmd += [item for profile in self.profiles for item in ["--profile", profile]]
if self.env_file:
docker_compose_cmd += ["--env-file", self.env_file]
for env_file in self.env_file:
docker_compose_cmd += ["--env-file", env_file]
return docker_compose_cmd

def waiting_for(self, strategies: dict[str, WaitStrategy]) -> "DockerCompose":
Expand Down