diff --git a/cli/command/formatter/image.go b/cli/command/formatter/image.go index d24bf50947ce..6182fe027c1c 100644 --- a/cli/command/formatter/image.go +++ b/cli/command/formatter/image.go @@ -246,7 +246,7 @@ func (c *imageContext) CreatedAt() string { } func (c *imageContext) Size() string { - return units.HumanSizeWithPrecision(float64(c.i.Size), 3) + return units.HumanSize(float64(c.i.Size)) } func (c *imageContext) Containers() string { diff --git a/opts/hosts.go b/opts/hosts.go index dcbbb7e78166..26624d1e2c45 100644 --- a/opts/hosts.go +++ b/opts/hosts.go @@ -57,7 +57,14 @@ func parseDockerDaemonHost(addr string) (string, error) { proto, host, hasProto := strings.Cut(addr, "://") if !hasProto && proto != "" { host = proto - proto = "tcp" + // If the address looks like a filesystem path, default to "unix" + // rather than "tcp" to avoid confusing errors when the user sets + // DOCKER_HOST=/path/to/sock without a unix:// prefix. + if strings.HasPrefix(host, "/") || strings.HasPrefix(host, "./") { + proto = "unix" + } else { + proto = "tcp" + } } switch proto { diff --git a/opts/hosts_test.go b/opts/hosts_test.go index 28f4eb6fab9e..36eff9a2d8de 100644 --- a/opts/hosts_test.go +++ b/opts/hosts_test.go @@ -79,6 +79,8 @@ func TestParseDockerDaemonHost(t *testing.T) { "unix://": "unix://" + defaultUnixSocket, "fd://": "fd://", "fd://something": "fd://something", + "/var/run/docker.sock": "unix:///var/run/docker.sock", + "./run/docker.sock": "unix://run/docker.sock", "localhost:": "tcp://localhost:2375", "localhost:5555": "tcp://localhost:5555", "localhost:5555/path": "tcp://localhost:5555/path",