2017-10-20 103 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)。