Skip to content

Commit f47292e

Browse files
authored
Use tty for running docker commands by default (#2260)
* Use tty for running docker commands by default * Add comment about using tty=False * Remove unrelated part
1 parent 929ebdb commit f47292e

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

tests/by_image/docker-stacks-foundation/test_user_options.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,10 @@ def test_set_uid(container: TrackedContainer) -> None:
175175
Additionally, verify that "--group-add=users" is suggested in a warning to restore
176176
write access.
177177
"""
178+
# This test needs to have tty disabled, the reason is explained here:
179+
# https://github.com/jupyter/docker-stacks/pull/2260#discussion_r2008821257
178180
logs = container.run_and_wait(
179-
timeout=5,
180-
no_warnings=False,
181-
user="1010",
182-
command=["id"],
181+
timeout=5, no_warnings=False, user="1010", command=["id"], tty=False
183182
)
184183
assert "uid=1010(jovyan) gid=0(root)" in logs
185184
warnings = TrackedContainer.get_warnings(logs)

tests/utils/tracked_container.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ def run_detached(self, **kwargs: Any) -> None:
4545
extending and/or overriding key/value pairs passed to the constructor
4646
"""
4747
LOGGER.info(f"Running {self.image_name} with args {kwargs} ...")
48+
default_kwargs = {"detach": True, "tty": True}
49+
final_kwargs = default_kwargs | kwargs
4850
self.container = self.docker_client.containers.run(
49-
self.image_name, **kwargs, detach=True
51+
self.image_name, **final_kwargs
5052
)
5153

5254
def get_logs(self) -> str:
@@ -64,7 +66,9 @@ def exec_cmd(self, cmd: str, **kwargs: Any) -> str:
6466
assert self.container is not None
6567
container = self.container
6668
LOGGER.info(f"Running cmd: `{cmd}` on container: {container.name}")
67-
exec_result = container.exec_run(cmd, **kwargs)
69+
default_kwargs = {"tty": True}
70+
final_kwargs = default_kwargs | kwargs
71+
exec_result = container.exec_run(cmd, **final_kwargs)
6872
output = exec_result.output.decode().rstrip()
6973
assert isinstance(output, str)
7074
LOGGER.info(f"Command output: {output}")

0 commit comments

Comments
 (0)