From f2059f1326924103eefe6088dbb1b94f8f8d1303 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Wed, 3 Dec 2025 10:55:40 +0100 Subject: [PATCH] improve usability by guessing API options based on defined parameters Signed-off-by: Nicolas De Loof --- lib/docker-client.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/docker-client.ts b/lib/docker-client.ts index fd0b3d0..3936c44 100644 --- a/lib/docker-client.ts +++ b/lib/docker-client.ts @@ -478,7 +478,11 @@ export class DockerClient { ): Promise { const response = await this.api.upgrade( `/containers/${id}/attach`, - options, + options || { + stdout: stdout != null, + stderr: stderr != null, + stream: stdout != null || stderr != null, + }, ); switch (response.content) { case DOCKER_RAW_STREAM: @@ -1641,6 +1645,18 @@ export class DockerClient { stderr: stream.Writable | null, execStartConfig?: types.ExecStartConfig, ): Promise { + // If no output streams and Detach not explicitly set, force detached mode + if ( + stdout === null && + stderr === null && + execStartConfig?.Detach === undefined + ) { + await this.api.post(`/exec/${id}/start`, { + ...execStartConfig, + Detach: true, + }); + return; + } if (execStartConfig?.Detach) { await this.api.post(`/exec/${id}/start`, execStartConfig); } else {