config.vm.define :web do |web_config| web_config.vm.box = "saucy" web_config.vm.host_name = "web" web_config.vm.network "private_network", ip:"192.168.100.10" end config.vm.define :db do |db_config| db_config.vm.box = "saucy" db_config.vm.host_name = "db" db_config.vm.network "private_network", ip:"192.168.100.20" end config.vm.provider :virtualbox do |vb| vb.customize ["modifyvm", :id, "--memory", "1024"] vb.customize ["modifyvm", :id, "--cpus", "2"] end
I have config two VM, 'db' and 'web'. Could I set different memory size for different VM?
Vagrant is able to define and control multiple guest machines per Vagrantfile. This is known as a "multi-machine" environment. These machines are generally able to work together or are somehow associated with each other.
Change memory limit for Vagrant. v. customize ["modifyvm", :id, "--memory", 4096] #<= 4096 equals 4GB total memory. # Set the box name in VirtualBox to match the working directory.
Vagrant is an open-source tool that allows you to create, configure, and manage boxes of virtual machines through an easy to use command interface. Essentially, it is a layer of software installed between a virtualization tool (such as VirtualBox, Docker, Hyper-V) and a VM.
2016-08-31: Updated answer to include the whole Vagrantfile per @DarkForce request.
You can do that by moving the vm.provider
definition inside each of the vm.define
blocks. For example this configuration sets the memory to 2048MB for "web" and 1024MB for "db":
# -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure(2) do |config| config.vm.box = "ubuntu/trusty64" config.vm.define :web do |web_config| web_config.vm.host_name = "web" web_config.vm.network "private_network", ip:"192.168.100.10" web_config.vm.provider :virtualbox do |vb| vb.customize ["modifyvm", :id, "--memory", "2048"] vb.customize ["modifyvm", :id, "--cpus", "2"] end end config.vm.define :db do |db_config| db_config.vm.host_name = "db" db_config.vm.network "private_network", ip:"192.168.100.20" db_config.vm.provider :virtualbox do |vb| vb.customize ["modifyvm", :id, "--memory", "1024"] vb.customize ["modifyvm", :id, "--cpus", "2"] end end end
Note: This example (like many in the Vagrant docs) will only work for VirtualBox. If you wanted your Vagrantfile to also work with VMware or another provider, the customization parameters would be listed separately. For example:
x.vm.provider "vmware_fusion" do |v| v.vmx["memsize"] = "3000" end x.vm.provider :virtualbox do |v| v.customize ["modifyvm", :id, "--memory", "3000"] end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With