Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions docker/opts/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ import (
"fmt"
"net"
"net/url"
"os"
"strconv"
"strings"
)

const (
dockerSocket = "/var/run/docker.sock"
podmanSocket = "/podman/podman.sock"
)

var (
// DefaultHTTPPort Default HTTP Port used if only the protocol is provided to -H flag e.g. dockerd -H tcp://
// These are the IANA registered port numbers for use with Docker
Expand All @@ -19,8 +25,7 @@ var (
// DefaultTLSHTTPPort Default HTTP Port used when TLS enabled
DefaultTLSHTTPPort = 2376 // Default TLS encrypted HTTP Port
// DefaultUnixSocket Path for the unix socket.
// Docker daemon by default always listens on the default unix socket
DefaultUnixSocket = "/var/run/docker.sock"
DefaultUnixSocket = getDefaultSocket()
// DefaultTCPHost constant defines the default host string used by docker on Windows
DefaultTCPHost = fmt.Sprintf("tcp://%s:%d", DefaultHTTPHost, DefaultHTTPPort)
// DefaultTLSHost constant defines the default host string used by docker for TLS sockets
Expand Down Expand Up @@ -166,3 +171,20 @@ func ValidateExtraHost(val string) (string, error) {
}
return val, nil
}

func getDefaultSocket() string {
_, err := os.Stat(dockerSocket)
if err == nil {
return dockerSocket
}
// see https://docs.podman.io/en/latest/markdown/podman-system-service.1.html#description
locations := []string{os.Getenv("XDG_RUNTIME_DIR"), "/run"} // rootless, rootful
for _, location := range locations {
_, err = os.Stat(location + podmanSocket)
if err == nil {
return location + podmanSocket
}
}

return dockerSocket
}
2 changes: 1 addition & 1 deletion dockertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func NewPool(endpoint string) (*Pool, error) {
endpoint = "http://localhost:2375"
}
} else {
endpoint = "unix:///var/run/docker.sock"
endpoint = options.DefaultHost
}
}

Expand Down