From c06c08531a5e6b531a04c2f614d4b36f3e610bc6 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 6 Oct 2025 21:15:14 +0200 Subject: [PATCH] cli/command/container: remove localhostDNSWarning This warning is better handled by the daemon, where applicable, as the client does not have all information available to determine if using a localhost / loopback-address for the DNS is possible. Signed-off-by: Sebastiaan van Stijn --- cli/command/container/create.go | 19 ------------------- cli/command/container/create_test.go | 10 ---------- ...container-create-localhost-dns-ipv6.golden | 1 - .../container-create-localhost-dns.golden | 1 - 4 files changed, 31 deletions(-) delete mode 100644 cli/command/container/testdata/container-create-localhost-dns-ipv6.golden delete mode 100644 cli/command/container/testdata/container-create-localhost-dns.golden diff --git a/cli/command/container/create.go b/cli/command/container/create.go index a2733ccf60..3faacc382a 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "net/netip" "os" "path" "strings" @@ -25,7 +24,6 @@ import ( "github.com/docker/cli/cli/trust" "github.com/docker/cli/internal/jsonstream" "github.com/docker/cli/opts" - "github.com/moby/moby/api/types/container" "github.com/moby/moby/api/types/mount" "github.com/moby/moby/api/types/versions" "github.com/moby/moby/client" @@ -361,10 +359,6 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c } } - if warn := localhostDNSWarning(*hostConfig); warn != "" { - response.Warnings = append(response.Warnings, warn) - } - containerID = response.ID for _, w := range response.Warnings { _, _ = fmt.Fprintln(dockerCli.Err(), "WARNING:", w) @@ -385,19 +379,6 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c return containerID, err } -// check the DNS settings passed via --dns against localhost regexp to warn if -// they are trying to set a DNS to a localhost address. -// -// TODO(thaJeztah): move this to the daemon, which can make a better call if it will work or not (depending on networking mode). -func localhostDNSWarning(hostConfig container.HostConfig) string { - for _, dnsIP := range hostConfig.DNS { - if addr, err := netip.ParseAddr(dnsIP); err == nil && addr.IsLoopback() { - return fmt.Sprintf("Localhost DNS (%s) may fail in containers.", addr) - } - } - return "" -} - func validatePullOpt(val string) error { switch val { case PullImageAlways, PullImageMissing, PullImageNever, "": diff --git a/cli/command/container/create_test.go b/cli/command/container/create_test.go index 6776f9c159..3307a3be3f 100644 --- a/cli/command/container/create_test.go +++ b/cli/command/container/create_test.go @@ -292,16 +292,6 @@ func TestNewCreateCommandWithWarnings(t *testing.T) { args: []string{"image:tag"}, warnings: []string{"warning from daemon", "another warning from daemon"}, }, - { - name: "container-create-localhost-dns", - args: []string{"--dns=127.0.0.11", "image:tag"}, - warning: true, - }, - { - name: "container-create-localhost-dns-ipv6", - args: []string{"--dns=::1", "image:tag"}, - warning: true, - }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { diff --git a/cli/command/container/testdata/container-create-localhost-dns-ipv6.golden b/cli/command/container/testdata/container-create-localhost-dns-ipv6.golden deleted file mode 100644 index bb07a137dc..0000000000 --- a/cli/command/container/testdata/container-create-localhost-dns-ipv6.golden +++ /dev/null @@ -1 +0,0 @@ -WARNING: Localhost DNS (::1) may fail in containers. diff --git a/cli/command/container/testdata/container-create-localhost-dns.golden b/cli/command/container/testdata/container-create-localhost-dns.golden deleted file mode 100644 index 409082ad6a..0000000000 --- a/cli/command/container/testdata/container-create-localhost-dns.golden +++ /dev/null @@ -1 +0,0 @@ -WARNING: Localhost DNS (127.0.0.11) may fail in containers.