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.

compose_filename = ["docker-compose-1.yml", "docker-compose-2.yml"]
with DockerCompose("/home/project", compose_file_name=compose_file_name, pull=True) as                     compose:
    host = compose.get_service_host("hub", 4444)
    port = compose.get_service_port("hub", 4444)
    driver = webdriver.Remote(
        command_executor=("http://{}:{}/wd/hub".format(host,port)),
        desired_capabilities=CHROME,
    )
    driver.get("http://automation-remarks.com")
    stdout, stderr = compose.get_logs()
    if stderr:
        print("Errors\n:{}".format(stderr))
hub:
image: selenium/hub
ports:
- "4444:4444"
firefox:
image: selenium/node-firefox
links:
    - hub
expose:
    - "5555"
chrome:
image: selenium/node-chrome
links:
    - hub
expose:
    - "5555"