Repository: gabrieldemarmiesse/python-on-whales (language: python)

Issue:
Allow interactive container to be detached
Running a container with `--interactive` (or `-i`) causes stdin to be open. This may be desirable for reasons entirely separate from whether you want to be attached/detached. For example, with `bash` as the entrypoint the container will exit if stdin is closed.

This is a hard blocker for my use-case, so I'm currently having to use a fork with this `ValueError` removed as per #343 (feel free to take over that draft PR, or let me know what's needed to get it ready for merge).


Discussion / hints:

Fix patch:
diff --git a/python_on_whales/components/container/cli_wrapper.py b/python_on_whales/components/container/cli_wrapper.py
index f62ed95f..f7dca645 100644
--- a/python_on_whales/components/container/cli_wrapper.py
+++ b/python_on_whales/components/container/cli_wrapper.py
@@ -1444,12 +1444,6 @@ def run(
 
         full_cmd.add_flag("--init", init)
 
-        # TODO: activate interactive and tty
-        if interactive and not tty:
-            raise NotImplementedError(
-                "Currently, docker.container.run(interactive=True) must have"
-                "tty=True. interactive=True and tty=False is not yet implemented."
-            )
         full_cmd.add_flag("--interactive", interactive)
         full_cmd.add_flag("--tty", tty)
 
@@ -1535,17 +1529,6 @@ def run(
                     "It's not possible to stream and detach a container at "
                     "the same time."
                 )
-            if interactive:
-                raise ValueError(
-                    "It's not possible to interact and detach a container at "
-                    "the same time."
-                )
-        if stream and interactive:
-            if interactive:
-                raise ValueError(
-                    "It's not possible to interact and stream a container at "
-                    "the same time."
-                )
         if detach:
             return Container(self.client_config, run(full_cmd))
         elif stream:


Test patch:
diff --git a/tests/python_on_whales/components/test_container.py b/tests/python_on_whales/components/test_container.py
index 979537fb..23ac629c 100644
--- a/tests/python_on_whales/components/test_container.py
+++ b/tests/python_on_whales/components/test_container.py
@@ -623,3 +623,8 @@ def test_prune():
     # container pruned
     docker.container.prune()
     assert container not in docker.container.list(all=True)
+
+
+def test_run_detached_interactive():
+    with docker.run("ubuntu", interactive=True, detach=True, tty=False) as c:
+        c.execute(["true"])