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
This commit is contained in:
Ayaz Salikhov
2025-03-22 17:46:38 +00:00
committed by GitHub
parent 929ebdb758
commit f47292edc0
2 changed files with 9 additions and 6 deletions

View File

@@ -175,11 +175,10 @@ def test_set_uid(container: TrackedContainer) -> None:
Additionally, verify that "--group-add=users" is suggested in a warning to restore
write access.
"""
# This test needs to have tty disabled, the reason is explained here:
# https://github.com/jupyter/docker-stacks/pull/2260#discussion_r2008821257
logs = container.run_and_wait(
timeout=5,
no_warnings=False,
user="1010",
command=["id"],
timeout=5, no_warnings=False, user="1010", command=["id"], tty=False
)
assert "uid=1010(jovyan) gid=0(root)" in logs
warnings = TrackedContainer.get_warnings(logs)

View File

@@ -45,8 +45,10 @@ class TrackedContainer:
extending and/or overriding key/value pairs passed to the constructor
"""
LOGGER.info(f"Running {self.image_name} with args {kwargs} ...")
default_kwargs = {"detach": True, "tty": True}
final_kwargs = default_kwargs | kwargs
self.container = self.docker_client.containers.run(
self.image_name, **kwargs, detach=True
self.image_name, **final_kwargs
)
def get_logs(self) -> str:
@@ -64,7 +66,9 @@ class TrackedContainer:
assert self.container is not None
container = self.container
LOGGER.info(f"Running cmd: `{cmd}` on container: {container.name}")
exec_result = container.exec_run(cmd, **kwargs)
default_kwargs = {"tty": True}
final_kwargs = default_kwargs | kwargs
exec_result = container.exec_run(cmd, **final_kwargs)
output = exec_result.output.decode().rstrip()
assert isinstance(output, str)
LOGGER.info(f"Command output: {output}")