如何在 Vagrant 中使用别名
How to use aliases in Vagrant
我正在尝试创建我可以在 Vagrant 中随时使用的别名 运行 虚拟机。我在网上找到了几个关于它的资源,但无法让它工作。我尝试在我的同步文件夹中制作一个 .bash_profile ,但这没有用。我注意到如果我 运行 命令别名 name="command" 这将起作用,但仅适用于当前会话。有人知道怎么做吗?我正在使用 macOS。感谢您的帮助!
这是我的 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
详情取决于客人的具体情况运行,但一些注意事项:
- 假设
vagrant ssh
的默认用户帐户处于活动状态,请确保将您希望覆盖的任何点文件复制到 /home/vagrant
。
- 如果覆盖
.bashrc
,请确保远程 shell 以交互标志启动(如果是这样,echo $-
将包括 i
)。
- 如果覆盖
.bash_profile
,请确保远程 shell 作为登录 shell 启动(如果是这样,echo $-
将包括 l
).
我正在尝试创建我可以在 Vagrant 中随时使用的别名 运行 虚拟机。我在网上找到了几个关于它的资源,但无法让它工作。我尝试在我的同步文件夹中制作一个 .bash_profile ,但这没有用。我注意到如果我 运行 命令别名 name="command" 这将起作用,但仅适用于当前会话。有人知道怎么做吗?我正在使用 macOS。感谢您的帮助!
这是我的 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
详情取决于客人的具体情况运行,但一些注意事项:
- 假设
vagrant ssh
的默认用户帐户处于活动状态,请确保将您希望覆盖的任何点文件复制到/home/vagrant
。 - 如果覆盖
.bashrc
,请确保远程 shell 以交互标志启动(如果是这样,echo $-
将包括i
)。 - 如果覆盖
.bash_profile
,请确保远程 shell 作为登录 shell 启动(如果是这样,echo $-
将包括l
).