fix(docker): treat containers from $DOCKER_HOST as local

This commit is contained in:
yusing
2025-09-03 10:31:13 +08:00
parent f47ba0a9b5
commit f81a2b6607

View File

@@ -7,6 +7,7 @@ import (
"maps"
"net"
"net/url"
"os"
"strconv"
"strings"
@@ -21,6 +22,8 @@ import (
var DummyContainer = new(types.Container)
var EnvDockerHost = os.Getenv("DOCKER_HOST")
var (
ErrNetworkNotFound = errors.New("network not found")
ErrNoNetwork = errors.New("no network found")
@@ -160,6 +163,10 @@ func isLocal(c *types.Container) bool {
if strings.HasPrefix(c.DockerHost, "unix://") {
return true
}
// treat it as local if the docker host is the same as the environment variable
if c.DockerHost == EnvDockerHost {
return true
}
url, err := url.Parse(c.DockerHost)
if err != nil {
return false