Skip to content

Commit

Permalink
docs: add documentation for Exec method
Browse files Browse the repository at this point in the history
Adds documentation for the Exec method in the DockerContainer struct.
This method executes a command in the current container and
returns the exit status of the executed command, an io.Reader containing
the combined stdout and stderr, and any encountered error.
The documentation emphasizes that reading directly from the io.Reader
may result in unexpected bytes due to custom stream multiplexing headers.
It recommends using stdcopy.StdCopy() from the Docker API to properly
separate the stdout and stderr.

See: https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/503
  • Loading branch information
gustavosbarreto committed Mar 27, 2024
1 parent 32f372c commit 17f5ee2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,13 @@ func (c *DockerContainer) NetworkAliases(ctx context.Context) (map[string][]stri
return a, nil
}

// Exec executes a command in the current container.
// It returns the exit status of the executed command, an `io.Reader` containing the combined
// stdout and stderr, and any encountered error. Note that reading directly from the `io.Reader`
// may result in unexpected bytes due to custom stream multiplexing headers.
// To separate the stdout and stderr from `io.Reader` and interpret these headers properly,
// `stdcopy.StdCopy()` from the Docker API should be used.
// More information about this can be found at: https://godoc.org/github.com/docker/docker/pkg/stdcopy
func (c *DockerContainer) Exec(ctx context.Context, cmd []string, options ...tcexec.ProcessOption) (int, io.Reader, error) {
cli := c.provider.client

Expand Down

0 comments on commit 17f5ee2

Please sign in to comment.