1

I am trying to execute a bash script on Windows with WSL1. This script contains a call to a command, like following:

script.sh:

echo $PATH
docker --version

after executing it from command line with bash script.sh, it returns the PATH, which includes the Windows path, including this Docker path:

/mnt/host/c/Program Files/Docker/Docker/resources/bin

Then returns command not found.

I do have Docker Desktop installed.

This also happens with any other command that should be in the Windows PATH. I guess I don't know how to integrate the Windows path into bash?

Cany anybody help me to know what I am doing wrong?

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
Pep Soler
  • 13
  • 4
  • Deleted my old answer and posted a new one based on your edit. It's much more clear now, at least, what you are asking. – NotTheDr01ds Feb 15 '22 at 18:58

1 Answers1

0

Short answer, try docker.exe --version but be aware of the caveats below in the "Details" section.


Details:

To summarize:

  • You are in WSL1
  • You have Docker Desktop installed in Windows
  • Your $PATH shows that the directory /mnt/host/c/Program Files/Docker/Docker/resources/bin is in the WSL search path.
  • Attempting to execute docker --version (or any other Windows command on the path) fails with command not found

As you seem to be aware, the Interop features of WSL (both versions 1 and 2):

  • Append the Windows path to your Linux path
  • Allow execution of Windows binaries

However, Linux does not have the concept of "file extensions" for determining whether or not something is executable. Under Linux, you do need to type the full filename, including the .exe extension, in order for it to execute.


Caveats

In general, remember that Windows commands are also going to need you to provide Windows paths. For instance, running notepad.exe ~/myfile isn't going to work because Windows doesn't have the concept of ~, or even /home/<yourusername> or any other Linux path. To Windows, that's going to be something like \\\\wsl\$\\<distroname>\\home\\<yourusername>\\myfile. (Side note: Don't create Linux files using Notepad anyway -- The line endings will be DOS/Windows instead of Unix/Linux.)

For Docker, in particular, note that you still need to run the Docker engine itself somewhere. This can either be:

  • A WSL2 instance that Docker Desktop creates and manages (the default, recommended)
  • A Hyper-V virtual machine (the "old way")
  • A remote Docker daemon that you point to via a DOCKER_HOST environment variable

In any event, it's not clear to me why you are attempting this from WSL1, since you'll still need for your Windows system to support virtualization in order to use either of the first two methods.

And for the third option, pointing to a remote host, you're going to run into an issue since Windows' executables can't (normally) pick up Linux environment variables. You'll need to look into WSLENV in order to handle this, if you need it.

In general, while you are going to be able to get docker.exe --version to work in WSL1, be aware that you are likely to run into other issues down the line with more complicated scenarios.

It's much preferred to run docker in WSL2. Docker Desktop will automatically link a docker (not docker.exe) into your WSL2 distribution which will be fully compatible with the Linux-side of things.

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70