Browse Source

mount /var/run/docker.sock for --use-api-socket

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 5 months ago
parent
commit
51acc58453
1 changed files with 4 additions and 6 deletions
  1. 4 6
      pkg/compose/apiSocket.go

+ 4 - 6
pkg/compose/apiSocket.go

@@ -18,8 +18,8 @@ package compose
 
 import (
 	"bytes"
+	"errors"
 	"fmt"
-	"strings"
 
 	"github.com/compose-spec/compose-go/v2/types"
 	"github.com/docker/cli/cli/config/configfile"
@@ -41,11 +41,9 @@ func (s *composeService) useAPISocket(project *types.Project) (*types.Project, e
 		return project, nil
 	}
 
-	socket := s.dockerCli.DockerEndpoint().Host
-	if !strings.HasPrefix(socket, "unix://") {
-		return nil, fmt.Errorf("use_api_socket can only be used with unix sockets: docker endpoint %s is incompatible", socket)
+	if s.dockerCli.ServerInfo().OSType == "windows" {
+		return nil, errors.New("use_api_socket can't be used with a Windows Docker Engine")
 	}
-	socket = strings.TrimPrefix(socket, "unix://") // should we confirm absolute path?
 
 	creds, err := s.dockerCli.ConfigFile().GetAllCredentials()
 	if err != nil {
@@ -69,7 +67,7 @@ func (s *composeService) useAPISocket(project *types.Project) (*types.Project, e
 		}
 		service.Volumes = append(service.Volumes, types.ServiceVolumeConfig{
 			Type:   types.VolumeTypeBind,
-			Source: socket,
+			Source: "/var/run/docker.sock",
 			Target: "/var/run/docker.sock",
 		})