10BC0 docs(client/ContainerExecAttach): add a mention to stdcopy.StdCopy by PowerPixel · Pull Request #50119 · moby/moby · GitHub
[go: up one dir, main page]

Skip to content

Conversation

PowerPixel
Copy link
Contributor

Add a mention to stdcopy.StdCopy to the documentation, as the stream returned in the HijackedResponse is multiplexed.

Closes #50118

- What I did
I added a mention to stdcopy.StdCopy to the documentation of the client.ContainerExecAttach method.

- How I did it
I simply added a few lines of documentation under the existing one for the client.ContainerExecAttach method.

- How to verify it

- Human readable description for the release notes

- A picture of a cute animal (not mandatory but encouraged)

Copy link
Contributor
@vvoland vvoland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment on lines 61 to 62
// The Reader contained in the hijacked connection should be read using
// the stdcopy.StdCopy function.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly (to make things even less intuitive) this is only true if the container was created with Tty = false.

Not 100% sure, so needs double checking 🙈

Copy link
Contributor Author
@PowerPixel PowerPixel Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this way, I'll add an additional comment later today. Thanks for the catch ! :)

if options.Tty {
stdout = outStream
} else {
stderr = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
stdout = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we have a similar doc on the ContainerAttach function:

// ContainerAttach attaches a connection to a container in the server.
// It returns a types.HijackedConnection with the hijacked connection
// and the a reader to get output. It's up to the called to close
// the hijacked connection by calling types.HijackedResponse.Close.
//
// The stream format on the response will be in one of two formats:
//
// If the container is using a TTY, there is only a single stream (stdout), and
// data is copied directly from the container output stream, no extra
// multiplexing or headers.
//
// If the container is *not* using a TTY, streams for stdout and stderr are
// multiplexed.
// The format of the multiplexed stream is as follows:
//
// [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4}[]byte{OUTPUT}
//
// STREAM_TYPE can be 1 for stdout and 2 for stderr
//
// SIZE1, SIZE2, SIZE3, and SIZE4 are four bytes of uint32 encoded as big endian.
// This is the size of OUTPUT.
//
// You can use github.com/docker/docker/pkg/stdcopy.StdCopy to demultiplex this
// stream.
func (cli *Client) ContainerAttach(ctx context.Context, containerID string, options container.AttachOptions) (types.HijackedResponse, error) {

I think we could partially reuse it here too (but spare the technical details and link to ContainerAttach for more details).

Copy link
Contributor Author
@PowerPixel PowerPixel Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vvoland Hey ! Sorry it took me a while to copy those few lines. :p This should be good, I copied the non-technical part of the documentation of ContainerExec and added a reference to it in the documentation for those who'd like to dwelve deeper in the technical details.

@vvoland vvoland added this to the 28.2.3 milestone Jun 2, 2025
@PowerPixel PowerPixel force-pushed the 50118-add-stdcopy-containerexecattach branch from 7528df3 to f65407d Compare June 10, 2025 21:06
@vvoland vvoland modified the milestones: 28.2.3, 28.3.0 Jun 11, 2025
Copy link
Contributor
@vvoland vvoland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

One last step: could you please rebase your branch on top of master and then squash your commits into one?

@PowerPixel PowerPixel force-pushed the 50118-add-stdcopy-containerexecattach branch 2 times, most recently from d71b6cc to 0de362a Compare June 16, 2025 16:51
@PowerPixel
Copy link
Contributor Author

Sorry, took me a while, this should be good now :)

Add a mention to stdcopy.StdCopy to the documentation, as the stream returned in the HijackedResponse is multiplexed when tty is disabled.

Signed-off-by: Medhy DOHOU <52136144+PowerPixel@users.noreply.github.com>
@PowerPixel PowerPixel force-pushed the 50118-add-stdcopy-containerexecattach branch from 0de362a to 4891396 Compare June 16, 2025 16:53
Copy link
Contributor
@vvoland vvoland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@vvoland vvoland merged commit a9c0420 into moby:master Jun 17, 2025
189 of 191 checks passed
@PowerPixel PowerPixel deleted the 50118-add-stdcopy-containerexecattach branch September 13, 2025 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docs: Add mention of stdcopy.StdCopy to ContainerExecAttach documentation
2 participants
0