Skip to content

Commit c06c085

Browse files
committed
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 <github@gone.nl>
1 parent 74e3520 commit c06c085

File tree

4 files changed

+0
-31
lines changed

4 files changed

+0
-31
lines changed

cli/command/container/create.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"io"
10-
"net/netip"
1110
"os"
1211
"path"
1312
"strings"
@@ -25,7 +24,6 @@ import (
2524
"github.com/docker/cli/cli/trust"
2625
"github.com/docker/cli/internal/jsonstream"
2726
"github.com/docker/cli/opts"
28-
"github.com/moby/moby/api/types/container"
2927
"github.com/moby/moby/api/types/mount"
3028
"github.com/moby/moby/api/types/versions"
3129
"github.com/moby/moby/client"
@@ -361,10 +359,6 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
361359
}
362360
}
363361

364-
if warn := localhostDNSWarning(*hostConfig); warn != "" {
365-
response.Warnings = append(response.Warnings, warn)
366-
}
367-
368362
containerID = response.ID
369363
for _, w := range response.Warnings {
370364
_, _ = fmt.Fprintln(dockerCli.Err(), "WARNING:", w)
@@ -385,19 +379,6 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
385379
return containerID, err
386380
}
387381

388-
// check the DNS settings passed via --dns against localhost regexp to warn if
389-
// they are trying to set a DNS to a localhost address.
390-
//
391-
// TODO(thaJeztah): move this to the daemon, which can make a better call if it will work or not (depending on networking mode).
392-
func localhostDNSWarning(hostConfig container.HostConfig) string {
393-
for _, dnsIP := range hostConfig.DNS {
394-
if addr, err := netip.ParseAddr(dnsIP); err == nil && addr.IsLoopback() {
395-
return fmt.Sprintf("Localhost DNS (%s) may fail in containers.", addr)
396-
}
397-
}
398-
return ""
399-
}
400-
401382
func validatePullOpt(val string) error {
402383
switch val {
403384
case PullImageAlways, PullImageMissing, PullImageNever, "":

cli/command/container/create_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,6 @@ func TestNewCreateCommandWithWarnings(t *testing.T) {
292292
args: []string{"image:tag"},
293293
warnings: []string{"warning from daemon", "another warning from daemon"},
294294
},
295-
{
296-
name: "container-create-localhost-dns",
297-
args: []string{"--dns=127.0.0.11", "image:tag"},
298-
warning: true,
299-
},
300-
{
301-
name: "container-create-localhost-dns-ipv6",
302-
args: []string{"--dns=::1", "image:tag"},
303-
warning: true,
304-
},
305295
}
306296
for _, tc := range testCases {
307297
t.Run(tc.name, func(t *testing.T) {

cli/command/container/testdata/container-create-localhost-dns-ipv6.golden

Lines changed: 0 additions & 1 deletion
This file was deleted.

cli/command/container/testdata/container-create-localhost-dns.golden

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)