From ea6760138c35c607a0b51ad041051374d8304e68 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Fri, 4 Mar 2022 11:59:48 +0100 Subject: [PATCH] wsContainersAttach attach to stdin/out/err streams as requested Signed-off-by: Nicolas De Loof --- api/server/router/container/container_routes.go | 15 +++++++++++---- api/types/backend/backend.go | 7 ++----- docs/api/version-history.md | 2 ++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/api/server/router/container/container_routes.go b/api/server/router/container/container_routes.go index b66bdac847..287611ad86 100644 --- a/api/server/router/container/container_routes.go +++ b/api/server/router/container/container_routes.go @@ -693,15 +693,22 @@ func (s *containerRouter) wsContainersAttach(ctx context.Context, w http.Respons return conn, conn, conn, nil } + useStdin, useStdout, useStderr := true, true, true + if versions.GreaterThanOrEqualTo(version, "1.42") { + useStdin = httputils.BoolValue(r, "stdin") + useStdout = httputils.BoolValue(r, "stdout") + useStderr = httputils.BoolValue(r, "stderr") + } + attachConfig := &backend.ContainerAttachConfig{ GetStreams: setupStreams, + UseStdin: useStdin, + UseStdout: useStdout, + UseStderr: useStderr, Logs: httputils.BoolValue(r, "logs"), Stream: httputils.BoolValue(r, "stream"), DetachKeys: detachKeys, - UseStdin: true, - UseStdout: true, - UseStderr: true, - MuxStreams: false, // TODO: this should be true since it's a single stream for both stdout and stderr + MuxStreams: false, // never multiplex, as we rely on websocket to manage distinct streams } err = s.backend.ContainerAttach(containerName, attachConfig) diff --git a/api/types/backend/backend.go b/api/types/backend/backend.go index db7a8d9011..50d203c0bb 100644 --- a/api/types/backend/backend.go +++ b/api/types/backend/backend.go @@ -17,11 +17,8 @@ type ContainerAttachConfig struct { Logs bool Stream bool DetachKeys string - - // Used to signify that streams are multiplexed and therefore need a StdWriter to encode stdout/stderr messages accordingly. - // TODO @cpuguy83: This shouldn't be needed. It was only added so that http and websocket endpoints can use the same function, and the websocket function was not using a stdwriter prior to this change... - // HOWEVER, the websocket endpoint is using a single stream and SHOULD be encoded with stdout/stderr as is done for HTTP since it is still just a single stream. - // Since such a change is an API change unrelated to the current changeset we'll keep it as is here and change separately. + // Used to signify that streams must be multiplexed by producer as endpoint can't manage multiple streams. + // This is typically set by HTTP endpoint, while websocket can transport raw streams MuxStreams bool } diff --git a/docs/api/version-history.md b/docs/api/version-history.md index dea3a82fc4..7e4807e05a 100644 --- a/docs/api/version-history.md +++ b/docs/api/version-history.md @@ -87,6 +87,8 @@ keywords: "API, Docker, rcli, REST, documentation" * The `Volume` type, as returned by `Added new `ClusterVolume` fields * Added a new `PUT /volumes{name}` endpoint to update cluster volumes (CNI). Cluster volumes are only supported if the daemon is a Swarm manager. +* `/containers/{name}/attach/ws` endpoint only attach to configured streams + according to `stdin`, `stdout` and `stderr` parameters. ## v1.41 API changes