@@ -62,6 +62,13 @@ func mustDelegateToMoby(ctxType string) bool {
6262 return false
6363}
6464
65+ func comDockerCli () string {
66+ if v := os .Getenv ("DOCKER_COM_DOCKER_CLI" ); v != "" {
67+ return v
68+ }
69+ return ComDockerCli
70+ }
71+
6572// Exec delegates to com.docker.cli if on moby context
6673func Exec (root * cobra.Command ) {
6774 childExit := make (chan bool )
@@ -92,13 +99,17 @@ func Exec(root *cobra.Command) {
9299
93100// RunDocker runs a docker command, and forward signals to the shellout command (stops listening to signals when an event is sent to childExit)
94101func RunDocker (childExit chan bool , args ... string ) error {
95- execBinary , err := resolvepath .LookPath (ComDockerCli )
96- if err != nil {
97- execBinary = findBinary (ComDockerCli )
98- if execBinary == "" {
99- fmt .Fprintln (os .Stderr , err )
100- fmt .Fprintln (os .Stderr , "Current PATH : " + os .Getenv ("PATH" ))
101- os .Exit (1 )
102+ execBinary := comDockerCli ()
103+ if execBinary == ComDockerCli {
104+ var err error
105+ execBinary , err = resolvepath .LookPath (ComDockerCli )
106+ if err != nil {
107+ execBinary = findBinary (ComDockerCli )
108+ if execBinary == "" {
109+ fmt .Fprintln (os .Stderr , err )
110+ fmt .Fprintln (os .Stderr , "Current PATH : " + os .Getenv ("PATH" ))
111+ os .Exit (1 )
112+ }
102113 }
103114 }
104115 cmd := exec .Command (execBinary , args ... )
@@ -149,7 +160,7 @@ func findBinary(filename string) string {
149160
150161// IsDefaultContextCommand checks if the command exists in the classic cli (issues a shellout --help)
151162func IsDefaultContextCommand (dockerCommand string ) bool {
152- cmd := exec .Command (ComDockerCli , dockerCommand , "--help" )
163+ cmd := exec .Command (comDockerCli () , dockerCommand , "--help" )
153164 b , e := cmd .CombinedOutput ()
154165 if e != nil {
155166 fmt .Println (e )
@@ -162,7 +173,7 @@ func ExecSilent(ctx context.Context, args ...string) ([]byte, error) {
162173 if len (args ) == 0 {
163174 args = os .Args [1 :]
164175 }
165- cmd := exec .CommandContext (ctx , ComDockerCli , args ... )
176+ cmd := exec .CommandContext (ctx , comDockerCli () , args ... )
166177 cmd .Stderr = os .Stderr
167178 return cmd .Output ()
168179}
0 commit comments