How to remote control Vagrant installed on Windows, within Linux Subsystem?

北城以北 提交于 2020-02-07 05:24:09

问题


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:

  1. When you are in bash, enter $ cmd.exe
  2. Perform your Vagrant commands, e.g.: C:\> vagrant up
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!