问题
According to the documentation of Vagrant, the topic WSL and Vagrant is advanced.
You need to install Vagrant on Linux, because:
While the vagrant.exe executable provided by the Vagrant Windows installation is accessible from within the WSL, it will not function as expected.
But I don't want to run Vagrant primarily in Linux. I would like to use Virtual Box, installed on my Windows 10 host. But I don't want to leave Linux bash, just to start Vagrant.
Is there a way to remote control Vagrant from within WSL?
回答1:
It is true, that $ vagrant.exe
would cause unexpected behaviour, because Vagrant (installed on Windows) is unable to handle unix-style paths.
But what actually works:
- When you are in bash, enter
$ cmd.exe
- Perform your Vagrant commands, e.g.:
C:\> vagrant up
- And return to bash, using
C:\> exit
Fortunately cmd.exe has got options, which allows us to call Vagrant via cmd.exe:
$ cmd.exe /c vagrant up
This will launch Windows' command line, perform the command, and return to bash.
Even more cool, when you add this to your ~/.bashrc file:
alias cmd='cmd.exe'
alias vagrant='cmd /c vagrant'
You can use the native vagrant commands in WSL bash (performed in Windows):
$ vagrant up
For me, this works like charm.
Notice: I've changed my root mount paths of harddrives from /mnt/c
to /c
. When I enter cmd.exe
I'll end up in the same directory. Windows does convert the paths. But Windows is not able to handle e.g. ~
. Then, Windows will end up in C:\Windows\System32
来源:https://stackoverflow.com/questions/58702052/how-to-remote-control-vagrant-installed-on-windows-within-linux-subsystem