I am using the Bash on Ubuntu on Windows, the way to run bash on Windows 10. I have the Creators update installed and the Ubuntu version is 16.04.
I was playing recently with things as npm, node.js and Docker and for docker I found it is possible to install it and run it in windows and just use the client part from bash, calling directly the docker.exe file from Windows's Program Files files folder. I just update my path variable to include the path to docker as PATH=$PATH:~/mnt/e/Program\ Files/Docker/
(put in .bashrc) and then I am able to run docker from bash calling docker.exe
.
But hey this bash and I dont want to write .exe at the end of the commands (programs). I can simply add an alias alias docker="docker.exe"
, but then I want to use lets say docker-compose and I have to add another one. I was thinking about adding a script to .bashrc that would go over path variable and search for .exe files in every path specified in the path variable and add an alias for every occurance, but it does not seem to be a very clean solution (but I guess it would serve its purpose quite well).
Is there a simple and clean solution to achieve this?
I've faced the same problem when trying to use Docker for Windows from WSL.
Had plenty of existing shell scripts that run fine under Linux and mostly under WSL too until failing due to
docker: command not found
. Changing everywheredocker
todocker.exe
would be too cumbersome and non-portable.Tried workaround with aliases in
~/.bashrc
as here at first:But it requires every script to be run in interactive mode and still doesn't work within backticks without script modification.
Then tried exported bash functions in
~/.bashrc
:This works. But it's still too tedious to add every needed exe.
Finally ended up with easier symlinks approach and a modified wslshim custom helper script.
Just add once to
~/.local/bin/wslshim
:Make it executable:
chmod +x ~/.local/bin/wslshim
Then adding any "alias" becomes as easy as typing two words:
The script auto picks up an absolute path to any windows executable in $PATH and symlinks it without extension into
~/.local/bin
which also resides in $PATH on WSL.This approach can be easily extended further to auto link any exe in a given directory if needed. But linking the whole $PATH would be an overkill. )
You should be able to simply set the executable directory to your PATH. Use export to persist.
Command: export PATH=$PATH:/path/to/directory/executable/is/located/in
In my windows 10 the solution was to install git-bash and docker for windows.
in this bash, when I press "docker" it works for example "docker ps" I didnt need to make an alias or change the path.
you can download git-bash from https://git-scm.com/download/win
then from Start button, search "git bash". Hope this solution good for you