- class DockerCompose(filepath: str, compose_file_name: str | Iterable = 'docker-compose.yml', pull: bool = False, build: bool = False, env_file: str | None = None)¶
Manage docker compose environments.
- Parameters:
filepath – Relative directory containing the docker compose configuration file.
compose_file_name – File name of the docker compose configuration file.
pull – Pull images before launching environment.
build – Build images referenced in the configuration file.
env_file – Path to an env file containing environment variables to pass to docker compose.
Example
This example spins up chrome and firefox containers using docker compose.
>>> from testcontainers.compose import DockerCompose >>> compose = DockerCompose("compose/tests", compose_file_name="docker-compose-4.yml", ... pull=True) >>> with compose: ... stdout, stderr = compose.get_logs() >>> b"Hello from Docker!" in stdout True
services: hello-world: image: "hello-world"