diff --git a/python_on_whales/components/compose/cli_wrapper.py b/python_on_whales/components/compose/cli_wrapper.py index f21d4ed5..18079e7d 100644 --- a/python_on_whales/components/compose/cli_wrapper.py +++ b/python_on_whales/components/compose/cli_wrapper.py @@ -499,6 +499,7 @@ def run( self, service: str, command: List[str] = [], + build: bool = False, detach: bool = False, # entrypoint: Optional[List[str]] = None, # envs: Dict[str, str] = {}, @@ -563,6 +564,7 @@ def run( "Try setting tty=False in docker.compose.run(...)." ) full_cmd = self.docker_compose_cmd + ["run"] + full_cmd.add_flag("--build", build) full_cmd.add_flag("--detach", detach) full_cmd.add_simple_arg("--name", name) full_cmd.add_flag("--no-TTY", not tty) diff --git a/tests/python_on_whales/components/test_compose.py b/tests/python_on_whales/components/test_compose.py index e7fc7d5a..aa8200da 100644 --- a/tests/python_on_whales/components/test_compose.py +++ b/tests/python_on_whales/components/test_compose.py @@ -860,3 +860,14 @@ def test_docker_compose_up_remove_orphans(): docker.compose.down(timeout=1) check_number_of_running_containers(docker, 0, compose_container_ids) remove(compose_file) + + +def test_docker_compose_run_build(): + docker.compose.run("my_service", build=True, detach=True, tty=False) + docker.compose.stop() + docker.compose.rm() + assert ( + docker.compose.config(return_json=True)["services"]["my_service"]["image"] + == docker.image.list("some_random_image")[0].repo_tags[0].split(":latest")[0] + ) + docker.image.remove("some_random_image", force=True)