2017-10-20 111 views
0

我试图创建别名,我可以在Vagrant中使用任何时间运行虚拟机。我在网上发现了几个关于它的来源,但无法让它工作。我试过在我的同步文件夹中创建一个.bash_profile文件,但那不起作用。我注意到,如果我运行命令别名name =“命令”,这将工作,但只适用于当前会话。有人知道怎么做吗?我正在使用macOS。谢谢你的帮助!如何使用Vagrant中的别名

这里是我的Vagrantfile:

# -*- mode: ruby -*- 
# vi: set ft=ruby : 

unless Vagrant.has_plugin?("vagrant-vbguest") 
    warn "\nWARNING: The vagrant-vbguest plugin should be installed or your shared folders might not mount properly!" 
    warn "You can do this by running the command 'vagrant plugin install vagrant-vbguest'.\n\n" 
end 

VAGRANTFILE_API_VERSION = "2" 

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 
    config.vm.box = "pype_vm" 
    config.vm.box_url = "https://.../pype_vm.json" 

    config.vm.network "private_network", ip: "" 
    config.vm.boot_timeout = 600 
    config.vm.provider "virtualbox" do |v| 
    # This forces VirtualBox to use the host's DNS resolver instead of 
    # VirtualBox's 
    v.customize ["modifyvm", :id, "", "on"] 

    # This enables the PAE/NX option, which resolved at least one user's 
    # issues with the VM hanging on boot 
    v.customize ["modifyvm", :id, "--pae", "on"] 

    # The RHEL VM was created with 2GB of memory to facilitate provisioning, 
    # but this is causing issues with certain workstations. This reduces 
    # the amount of memory allocated to the VM but should not impact development 
    # performance. The number is in MB and can be increased if desired. 
    v.memory = 1024 
    end 
    # Share an additional folder to the guest VM. 
    config.vm.synced_folder File.dirname(__FILE__), "/pype" 
end 
+0

别名是一种交互式工具 - 它们不适用于非交互式shell。你的用例有哪些细节? –

+0

(如果你正在容器中运行一个交互式shell,你需要确保你的'.bash_profile'在容器*内*)。 –

+0

...顺便说一句,我强烈建议使用导出的函数,而不是;通过这种方式,它可以作为子进程运行。仔细一点,您甚至可以将定义放入您的Vagrantfile中作为环境变量。 –

回答

0

的细节取决于客户的具体运行的,但是一些注意事项:

  • 假设默认用户帐户vagrant ssh处于活动状态,确保您希望覆盖的任何点文件将被复制到/home/vagrant
  • 如果覆盖.bashrc,请确保远程外壳使用交互式标志启动(如果是这样,echo $-将包含i)。
  • 如果覆盖.bash_profile,请确保远程shell是作为登录shell启动的(如果是这样,echo $-将包含l)。