diff options
author | Paweł Gronowski <pawel.gronowski@docker.com> | 2022-05-12 14:54:44 +0200 |
---|---|---|
committer | Paweł Gronowski <pawel.gronowski@docker.com> | 2022-05-19 07:57:27 +0200 |
commit | 85a7f5a09af9c2d387c89df4d9de61c4322a2843 (patch) | |
tree | fcaa79645c8c65f160906fd5a6c5ef4636cdb057 /integration | |
parent | 1a0587bd766e3ab1f6dbe808a94a41a2f54d9126 (diff) | |
download | docker-85a7f5a09af9c2d387c89df4d9de61c4322a2843.tar.gz |
daemon/linux: Set console size on creation
On Linux the daemon was not respecting the HostConfig.ConsoleSize
property and relied on cli initializing the tty size after the container
was created. This caused a delay between container creation and
the tty actually being resized.
This is also a small change to the api description, because
HostConfig.ConsoleSize is no longer Windows-only.
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Diffstat (limited to 'integration')
-rw-r--r-- | integration/container/run_linux_test.go | 31 | ||||
-rw-r--r-- | integration/internal/container/ops.go | 7 |
2 files changed, 38 insertions, 0 deletions
diff --git a/integration/container/run_linux_test.go b/integration/container/run_linux_test.go index 11873e8e02..bd1fc6e932 100644 --- a/integration/container/run_linux_test.go +++ b/integration/container/run_linux_test.go @@ -1,13 +1,16 @@ package container // import "github.com/docker/docker/integration/container" import ( + "bytes" "context" + "io" "os" "path/filepath" "strings" "testing" "time" + "github.com/docker/docker/api/types" containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/versions" "github.com/docker/docker/integration/internal/container" @@ -183,3 +186,31 @@ func TestPrivilegedHostDevices(t *testing.T) { assert.Check(t, is.Equal(strings.TrimSpace(res.Stdout()), devRootOnlyTest)) } } + +func TestConsoleSize(t *testing.T) { + skip.If(t, testEnv.DaemonInfo.OSType != "linux") + skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.42"), "skip test from new feature") + + defer setupTest(t)() + client := testEnv.APIClient() + ctx := context.Background() + + cID := container.Run(ctx, t, client, + container.WithTty(true), + container.WithImage("busybox"), + container.WithCmd("stty", "size"), + container.WithConsoleSize(57, 123), + ) + + poll.WaitOn(t, container.IsStopped(ctx, client, cID), poll.WithDelay(100*time.Millisecond)) + + out, err := client.ContainerLogs(ctx, cID, types.ContainerLogsOptions{ShowStdout: true}) + assert.NilError(t, err) + defer out.Close() + + var b bytes.Buffer + _, err = io.Copy(&b, out) + assert.NilError(t, err) + + assert.Equal(t, strings.TrimSpace(b.String()), "123 57") +} diff --git a/integration/internal/container/ops.go b/integration/internal/container/ops.go index 0a600361aa..0d94a4ebf7 100644 --- a/integration/internal/container/ops.go +++ b/integration/internal/container/ops.go @@ -227,3 +227,10 @@ func WithIsolation(isolation containertypes.Isolation) func(*TestContainerConfig c.HostConfig.Isolation = isolation } } + +// WithConsoleSize sets the initial console size of the container +func WithConsoleSize(width, height uint) func(*TestContainerConfig) { + return func(c *TestContainerConfig) { + c.HostConfig.ConsoleSize = [2]uint{height, width} + } +} |