瀏覽代碼

wsContainersAttach attach to stdin/out/err streams as requested

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Nicolas De Loof 3 年之前
父節點
當前提交
ea6760138c
共有 3 個文件被更改,包括 15 次插入9 次删除
  1. 11 4
      api/server/router/container/container_routes.go
  2. 2 5
      api/types/backend/backend.go
  3. 2 0
      docs/api/version-history.md

+ 11 - 4
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
 		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{
 	attachConfig := &backend.ContainerAttachConfig{
 		GetStreams: setupStreams,
 		GetStreams: setupStreams,
+		UseStdin:   useStdin,
+		UseStdout:  useStdout,
+		UseStderr:  useStderr,
 		Logs:       httputils.BoolValue(r, "logs"),
 		Logs:       httputils.BoolValue(r, "logs"),
 		Stream:     httputils.BoolValue(r, "stream"),
 		Stream:     httputils.BoolValue(r, "stream"),
 		DetachKeys: detachKeys,
 		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)
 	err = s.backend.ContainerAttach(containerName, attachConfig)

+ 2 - 5
api/types/backend/backend.go

@@ -17,11 +17,8 @@ type ContainerAttachConfig struct {
 	Logs       bool
 	Logs       bool
 	Stream     bool
 	Stream     bool
 	DetachKeys string
 	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
 	MuxStreams bool
 }
 }
 
 

+ 2 - 0
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 
 * The `Volume` type, as returned by `Added new `ClusterVolume` fields 
 * Added a new `PUT /volumes{name}` endpoint to update cluster volumes (CNI).
 * Added a new `PUT /volumes{name}` endpoint to update cluster volumes (CNI).
   Cluster volumes are only supported if the daemon is a Swarm manager.
   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
 ## v1.41 API changes