Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

CLI issues with ZSH on OS X: "com.docker.cli: executable file not found" #754

Closed
bwateratmsft opened this issue Oct 9, 2020 · 30 comments · Fixed by #1826
Closed

CLI issues with ZSH on OS X: "com.docker.cli: executable file not found" #754

bwateratmsft opened this issue Oct 9, 2020 · 30 comments · Fixed by #1826
Assignees
Labels
bug: regression ↩️ A new version of the app broke something.

Comments

@bwateratmsft
Copy link

Description

Several users using ZSH on OS X have reported an error when running commands in VSCode (microsoft/vscode-docker#2366). The commands run are typically done with zsh -c 'docker build ...' internally by VSCode.

Related:
docker/for-mac#4956

Steps to reproduce the issue:

  1. Install Docker Desktop for Mac 2.4.0.0.
  2. Run zsh -c 'docker some command'

Describe the results you received:
"exec: "com.docker.cli": executable file not found in $PATH".

Describe the results you expected:
Successful execution of the command

Workaround:
Disabling the "Cloud Experience" in settings has worked for these users.

@gtardif
Copy link
Contributor

gtardif commented Oct 13, 2020

@sergeyk @HannesOberreiter maybe you will have some useful information to help us investigate further.
If you can still reproduce the issue (after activating "Enable cloud experience" in Docker Desktop preferences), could you try to run these commands from a terminal:

zsh -c 'which docker'
zsh -c 'which com.docker.cli'
# These 2 commands should be under /usr/local/bin/ with Docker Desktop setup

# Don't copy the entire PATH value in this ticket, just check if it contains /usr/local/bin/
zsh -c 'echo $PATH'

# to reproduce the issue
zsh -c 'docker ps'

Thanks for your feedback

@HannesOberreiter
Copy link

HannesOberreiter commented Oct 13, 2020

@gtardif I get the same error after activating "Enable cloud experience" again.

> Executing task: docker run --rm -it  -p 8888:8888/tcp hannesoberreiter/tug-python362:latest <

exec: "com.docker.cli": executable file not found in $PATH
The terminal process "/bin/zsh '-c', 'docker run --rm -it  -p 8888:8888/tcp hannesoberreiter/tug-python362:latest'" failed to launch (exit code: 1).

Terminal will be reused by tasks, press any key to close it.

Your test seems fine and the command zsh -c 'docker ps' also works in the integrated console.

> zsh -c 'which docker'
/usr/local/bin/docker
> zsh -c 'which com.docker.cli'
/usr/local/bin/com.docker.cli
> zsh -c 'echo $PATH' | grep "/usr/local/bin" -o
/usr/local/bin
> zsh -c 'docker ps'
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Cheers
Hannes

@chris-crone chris-crone added the bug: regression ↩️ A new version of the app broke something. label Oct 20, 2020
@chris-crone
Copy link
Contributor

This can be reproduced using konvoy. The source for that isn't public but I managed to see how they're shelling out to Docker using a script:

#!/bin/sh
set -xe

env >&2 
/usr/local/bin/docker "${@}"

Running konvoy, I see that it does not set the PATH:

+ env
KONVOY_EXECUTABLE_DIR=/opt/konvoy/artifacts
KUBECONFIG=/Users/chris/.kube/config
PWD=/private/tmp/konvoy/konvoy_v1.5.2
SHLVL=1
KONVOY_USER_OS=darwin
KONVOY_COMMAND_ARG=./konvoy
_=/usr/bin/env
+ /usr/local/bin/docker run --interactive --tty=true --rm --net=host -w /tmp/konvoy/konvoy_v1.5.2 -u 501:20 --group-add 0 -e KUBECONFIG -e SSH_AUTH_SOCK -e KONVOY_EXECUTABLE_DIR -e KONVOY_COMMAND_ARG -e KONVOY_USER_OS --mount type=volume,source=ssh-agent,target=/ssh-agent --mount type=bind,source=/tmp/konvoy/konvoy_v1.5.2,target=/tmp/konvoy/konvoy_v1.5.2 --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock --mount type=bind,source=/Users/chris,target=/Users/chris --mount type=bind,source=/tmp/konvoy/konvoy_v1.5.2/.konvoy-tmp954516335/passwd,target=/etc/passwd --mount type=bind,source=/tmp/konvoy/konvoy_v1.5.2/.konvoy-tmp954516335/group,target=/etc/group --mount type=bind,source=/tmp/konvoy/konvoy_v1.5.2/.konvoy-tmp954516335/ssh_config,target=/Users/chris/.ssh/config --mount type=bind,source=/tmp/konvoy/konvoy_v1.5.2/.konvoy-tmp954516335/ssh_known_hosts,target=/Users/chris/.ssh/known_hosts --mount type=bind,source=/tmp/konvoy/konvoy_v1.5.2,target=/opt/konvoy/artifacts mesosphere/konvoy:v1.5.2
Deploy and manage Kubernetes clusters

Usage:
  konvoy [command]

Possible workaround is for the Compose CLI to check if com.docker.cli is in the PATH, otherwise fallback to trying next to itself.

@ulyssessouza ulyssessouza self-assigned this Oct 21, 2020
@pvam
Copy link

pvam commented Oct 22, 2020

recently upgraded to 2.3.0.4 and facing same issue. Im on OSX + Zsh.
Unfortunately i'm not able to turn off the Cloud feature that other people suggested as workaround. When i try to do so via UI, the screen turns white and unresponsive.

Downgrading to 2.3.0.2 worked for me.

@chris-crone
Copy link
Contributor

Possibly related to the VS Code case, on restarting my Mac, I see this error for Go tooling which shows that my PATH has not been set correctly:
Screen Shot 2020-10-29 at 13 47 36

@ulyssessouza ulyssessouza removed their assignment Nov 6, 2020
@jonathanhuston
Copy link

I get the same error on macOS Catalina 10.15.7, VSCode 1.51.0, Docker extension 1.7.0, and Docker Desktop 2.5.0.1 (updated today). Disabling "cloud experience" also remedies the error (thanks for that).

@chris-crone
Copy link
Contributor

We're still struggling to reproduce this with VSCode. @jonathanhuston did you try restarting VSCode and/or your machine before deactivating the cloud experience?

@jonathanhuston
Copy link

@chris-crone Rebooting Mac, VSCode, Docker extension had no effect. After disabling "cloud experience" (and restarting Docker Desktop), the problem disappeared immediately, even without restarting VSCode.

@karolz-ms
Copy link
Contributor

@gtardif @chris-crone we had more users reporting that they still suffer from this issue, see microsoft/vscode-docker#2894

The workaround of disabling "cloud experience" (new CLI) is no longer viable because that option has been removed in recent Docker Desktop releases... 😔

@chris-crone
Copy link
Contributor

@gtardif In the case of this error, could we print out the user's PATH so that we can see if that's the issue?

@karolz-ms I see that this occurs when triggering Docker commands from the VS Code plugin, what is happening under the hood?

@karolz-ms
Copy link
Contributor

We launch docker run ... command using VS Code "shell" type of task https://github.com/microsoft/vscode-docker/blob/main/src/utils/executeAsTask.ts#L30 and we refer to the CLI as docker (launching whatever is found on PATH)

@alexr00 would you be able to point Chris and Guillaume to the code that handles the process launch for ShellExecution type of tasks?

@alexr00
Copy link

alexr00 commented Apr 28, 2021

VS Code shell execution tasks are launched with terminal with -c for zsh as described above. For most shells, this results in a non-login, non-interactive shell, which means that the user's shell startup scripts are not run. Since these startup scripts often result in setting environment variables, you can end up with a different environment.

VS Code tries to improve this by copying VS Code's environment to the task shell.

One thing to check: is the environment variable you care about set the way you'd expect for VS Code? You can check this by opening the dev tools in VS Code (command Developer: Toggle Developer Tools) and using the console to print process.env.

There isn't one good place for me to point you at for how VS Code handles this process launch.

@MattRiddell
Copy link

printing out my process.env.PATH as described above includes /usr/local/bin/ and running the earlier commands in the build in terminal yields:

❯ which docker
/usr/local/bin/docker
❯ which com.docker.cli
/usr/local/bin/com.docker.cli
❯ docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED       STATUS         PORTS                  NAMES

@MattRiddell
Copy link

If I copy the command it says it couldn't run and paste it into the inbuilt terminal it runs fine:

zsh '-c', 'docker build --pull --rm -f "Dockerfile" -t x:latest "."'

I have to remove the comma between the zsh command and the docker build - I'm assuming that's just command and arguments.

@Dids
Copy link

Dids commented May 24, 2021

Are there any known workarounds for this and is this still being actively worked on?
The original issue has been around for quite a while and I'd imagine it's impacting a lot of us developers out there.

@brianoflondon
Copy link

I've just started trying to use Docker and seem to have hit it. I can type

docker build -t podping-hivewriter:develop .

into the terminal in VSCode without a problem, but right click and Build Image... gives me the same error described here.

> Executing task: docker build --pull --rm -f "Dockerfile" -t podpinghivewriter:develop "." <

exec: "com.docker.cli": executable file not found in $PATH
The terminal process "/bin/zsh '-c', 'docker build --pull --rm -f "Dockerfile" -t podpinghivewriter:develop "."'" terminated with exit code: 1.

If I directly copy paste the entire line above into the terminal, still within VSCode it works.

docker build --pull --rm -f "Dockerfile" -t podpinghivewriter:develop "." 
[+] Building 17.8s (11/11) FINISHED                                                                                
 => [internal] load build definition from Dockerfile                                                          0.0s
 => => transferring dockerfile: 37B                                                                           0.0s
 => [internal] load .dockerignore                                                                             

Just putting this here in case another report helps.

@blindpirate
Copy link

I have to downgrade to 3.1.0 to workaround this issue. This is sad.

@brianoflondon
Copy link

This issue has cleared up for me with the latest version of VSCode. I did nothing and now right click build Docker works.

Version: 1.57.0
Commit: b4c1bd0a9b03c749ea011b06c6d2676c8091a70c
Date: 2021-06-09T17:22:31.215Z (4 days ago)
Electron: 12.0.9
Chrome: 89.0.4389.128
Node.js: 14.16.0
V8: 8.9.255.25-electron.0
OS: Darwin x64 20.5.0

@MattRiddell
Copy link

Yep, working for me here too on the latest version of VSCode

@mat007
Copy link
Contributor

mat007 commented Jun 21, 2021

Anyone running at least Desktop 3.3.0 is still experiencing this issue?

@RobYed
Copy link

RobYed commented Jun 21, 2021

Yes, I am still experiencing it at
Docker 3.3.0
on MacOS 11.3.1 with ZSH

I don't use VS Code, but IntelliJ. So I do not profit from the workaround the VS Code Team implemented.

It is a big annoyance in my every day work.

@phocheng
Copy link

phocheng commented Aug 3, 2021

me too.
% docker -v
Docker version 20.10.7, build f0df350
% which com.docker.cli
/usr/local/bin/com.docker.cli
% echo $PATH|grep /usr/local/bin -o
/usr/local/bin

Mac version: 11.4
Error in IntelliJ:
exec: "com.docker.cli": executable file not found in $PATH

@thersitz
Copy link

thersitz commented Sep 6, 2021

Using MacOS 11.5.2. Ran diagnosis from support tab and the report shows:

2 failures detected
1 : is the $PATH ok?
Failed with: unable to find docker executable on PATH
The directory containing the docker CLI tools must be on the $PATH

2 : is the VM networking working?
Failed with: network checks failed: failed to ping host: exit status 1
VM seems to have a network connectivity issue. Please check your host firewall and anti-virus settings in case they are blocking the VM.

Number two disappeared after I turned off Norton VPN and reinstalled.

Just installed Docker Desktop on this machine. Created a debian containing and installed apache on it but then started getting "the executable file not found in $PATH"

@alanwilter
Copy link

I'm using all the latest:

Big Sur macOS 11.6

Version: 1.60.2
Commit: 7f6ab5485bbc008386c4386d08766667e155244e
Date: 2021-09-22T11:59:27.195Z
Electron: 13.1.8
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Darwin x64 20.6.0

Docker version 20.10.8, build 3967b7d

And I do have the same issue:

> Executing task: docker-compose -f "docker-compose.yml" down <

zsh:1: command not found: docker-compose
The terminal process "/bin/zsh '-c', 'docker-compose -f "docker-compose.yml" down'" terminated with exit code: 127.

The only "workaround" I know is to start vscode via CLI code in my iTerm2 terminal.

Absolutely annoying.

@karolz-ms
Copy link
Contributor

@alanwilter VS COde docker extension now exposes docker.dockerPath setting which lets you specify absolute path to Docker executable. It is a workaround, not a true fix (that would be on Apple or Docker), but at least makes the Docker VS Code extension work regardless how VS Code was started.

@alanwilter
Copy link

Thanks a lot @karolz-ms ! For me it's a proper solution.

@alanwilter
Copy link

Sorry again.

But then I have tasks like:

{
            "label": "DC_down",
            "type": "shell",
            "command": "docker compose down",
            "problemMatcher": [],
        }

that used to work just fine but now are failing with:

> Executing task: docker compose down <

zsh:1: command not found: docker
The terminal process "zsh '-c', 'docker compose down'" terminated with exit code: 127.

Why the shell is not working anymore? I have set docker.dockerPath but it seems that tasks.json shell does not read from there. It's extremely frustrating, sorry.

@karolz-ms
Copy link
Contributor

@alanwilter this is because docker.dockerPath is a setting that only VS Code Docker extension "understands". If you run ordinary docker CLI from the shell (like in the task you quoted), the workaround is not applied.

What might help, is that VS Code Docker extension provides its own task for Compose: https://code.visualstudio.com/docs/containers/reference#_docker-compose-task This task should respect docker.dockerPath setting. Let me know if that helps!

@bwateratmsft
Copy link
Author

@alanwilter this is because docker.dockerPath is a setting that only VS Code Docker extension "understands". If you run ordinary docker CLI from the shell (like in the task you quoted), the workaround is not applied.

What might help, is that VS Code Docker extension provides its own task for Compose: https://code.visualstudio.com/docs/containers/reference#_docker-compose-task This task should respect docker.dockerPath setting. Let me know if that helps!

Hm, actually I don't think it will use docker.dockerPath: https://github.com/microsoft/vscode-docker/blob/main/src/docker/Contexts.ts#L37-L39

@alanwilter
Copy link

@karolz-ms Yep, I ended up using your first link. But for some more complex tasks I simply put the full path for docker... still, quite annoying to keep "hacking" VSCode.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: regression ↩️ A new version of the app broke something.
Projects
None yet