@@ -24,7 +24,7 @@ import (
2424)
2525
2626const (
27- DefaultSocketPath = "/var/ run/docker.sock"
27+ DefaultSocketPath = "/run/docker.sock"
2828 DefaultTimeout = 2 * time .Second
2929)
3030
@@ -33,7 +33,13 @@ type Client struct {
3333}
3434
3535func NewDockerClient (path string ) (* Client , error ) {
36+ host := path
37+ if protoAddrParts := strings .SplitN (host , "://" , 2 ); len (protoAddrParts ) == 1 {
38+ // The default protocol is unix sockets (tcp and http are also valid).
39+ host = "unix://" + host
40+ }
3641 cli , err := client .NewClientWithOpts (
42+ client .WithHost (host ),
3743 client .WithAPIVersionNegotiation (),
3844 client .WithDialContext (func (ctx context.Context , network , addr string ) (net.Conn , error ) {
3945 return net .DialTimeout ("unix" , path , DefaultTimeout )
@@ -65,7 +71,7 @@ func (c *Client) PIDFromContainerID(containerID string) (int, error) {
6571
6672 containerJSON , err := c .client .ContainerInspect (context .Background (), containerID )
6773 if err != nil {
68- return - 1 , err
74+ return - 1 , fmt . Errorf ( "failed to get container status, container id: %s: %w" , containerID , err )
6975 }
7076
7177 if containerJSON .State == nil {
0 commit comments