Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fall back to podman if available #452

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 24 additions & 2 deletions docker/opts/hosts.go
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
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