From 08552809a06a4d944e11fafd5b47825576d61718 Mon Sep 17 00:00:00 2001 From: Josh Hawn Date: Wed, 2 Aug 2017 14:35:03 -0700 Subject: [PATCH] Enable TCP Keep-Alive in Docker client Some network environments may have NATs, proxies, or gateways which kill idle connections. There are many Docker API operations which may be idle for long periods of time (such as ContainerWait and ContainerAttach) and may result in unexpected connection closures or hangs if TCP keepalives are not used. This patch updates the default HTTP transport used by the Docker client package to enable TCP Keep-Alive with a keep-alive interval of 30 seconds. It also sets a connect timeout of 30 seconds. Docker-DCO-1.1-Signed-off-by: Josh Hawn (github: jlhawn) (cherry picked from commit 2831a04cbad65e11081b0cd189599767fce3646a) Signed-off-by: Sebastiaan van Stijn --- components/cli/cli/command/cli.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/cli/cli/command/cli.go b/components/cli/cli/command/cli.go index 59efa9ac2a..10948608a2 100644 --- a/components/cli/cli/command/cli.go +++ b/components/cli/cli/command/cli.go @@ -3,9 +3,11 @@ package command import ( "fmt" "io" + "net" "net/http" "os" "runtime" + "time" "github.com/docker/cli/cli" cliconfig "github.com/docker/cli/cli/config" @@ -285,6 +287,10 @@ func newHTTPClient(host string, tlsOptions *tlsconfig.Options) (*http.Client, er } tr := &http.Transport{ TLSClientConfig: config, + DialContext: (&net.Dialer{ + KeepAlive: 30 * time.Second, + Timeout: 30 * time.Second, + }).DialContext, } proto, addr, _, err := client.ParseHost(host) if err != nil {