summaryrefslogtreecommitdiff
path: root/api/server
diff options
context:
space:
mode:
authorPaweł Gronowski <pawel.gronowski@docker.com>2022-06-15 09:28:20 +0200
committerPaweł Gronowski <pawel.gronowski@docker.com>2022-06-24 11:54:25 +0200
commit56a20dbc19786633f605d3871f5242d8e0f1be5a (patch)
tree643532f01a56d1a491194fbcef31ba12432d4b1f /api/server
parent9c4987ee6b236de5e8ec213f7872fb3b9ee1aece (diff)
downloaddocker-56a20dbc19786633f605d3871f5242d8e0f1be5a.tar.gz
container/exec: Support ConsoleSize
Now client have the possibility to set the console size of the executed process immediately at the creation. This makes a difference for example when executing commands that output some kind of text user interface which is bounded by the console dimensions. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Diffstat (limited to 'api/server')
-rw-r--r--api/server/router/container/backend.go2
-rw-r--r--api/server/router/container/exec.go28
2 files changed, 28 insertions, 2 deletions
diff --git a/api/server/router/container/backend.go b/api/server/router/container/backend.go
index 6145c51de1..4db989a102 100644
--- a/api/server/router/container/backend.go
+++ b/api/server/router/container/backend.go
@@ -17,7 +17,7 @@ type execBackend interface {
ContainerExecCreate(name string, config *types.ExecConfig) (string, error)
ContainerExecInspect(id string) (*backend.ExecInspect, error)
ContainerExecResize(name string, height, width int) error
- ContainerExecStart(ctx context.Context, name string, stdin io.Reader, stdout io.Writer, stderr io.Writer) error
+ ContainerExecStart(ctx context.Context, name string, options container.ExecStartOptions) error
ExecExists(name string) (bool, error)
}
diff --git a/api/server/router/container/exec.go b/api/server/router/container/exec.go
index 3187fe6c83..b86af42d7f 100644
--- a/api/server/router/container/exec.go
+++ b/api/server/router/container/exec.go
@@ -9,6 +9,7 @@ import (
"github.com/docker/docker/api/server/httputils"
"github.com/docker/docker/api/types"
+ "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/stdcopy"
@@ -46,6 +47,12 @@ func (s *containerRouter) postContainerExecCreate(ctx context.Context, w http.Re
return execCommandError{}
}
+ version := httputils.VersionFromContext(ctx)
+ if versions.LessThan(version, "1.42") {
+ // Not supported by API versions before 1.42
+ execConfig.ConsoleSize = nil
+ }
+
// Register an instance of Exec in container.
id, err := s.backend.ContainerExecCreate(vars["name"], execConfig)
if err != nil {
@@ -88,6 +95,18 @@ func (s *containerRouter) postContainerExecStart(ctx context.Context, w http.Res
return err
}
+ if execStartCheck.ConsoleSize != nil {
+ // Not supported before 1.42
+ if versions.LessThan(version, "1.42") {
+ execStartCheck.ConsoleSize = nil
+ }
+
+ // No console without tty
+ if !execStartCheck.Tty {
+ execStartCheck.ConsoleSize = nil
+ }
+ }
+
if !execStartCheck.Detach {
var err error
// Setting up the streaming http interface.
@@ -121,9 +140,16 @@ func (s *containerRouter) postContainerExecStart(ctx context.Context, w http.Res
}
}
+ options := container.ExecStartOptions{
+ Stdin: stdin,
+ Stdout: stdout,
+ Stderr: stderr,
+ ConsoleSize: execStartCheck.ConsoleSize,
+ }
+
// Now run the user process in container.
// Maybe we should we pass ctx here if we're not detaching?
- if err := s.backend.ContainerExecStart(context.Background(), execName, stdin, stdout, stderr); err != nil {
+ if err := s.backend.ContainerExecStart(context.Background(), execName, options); err != nil {
if execStartCheck.Detach {
return err
}