The main advantage of working with a virtual machine is that you can quickly get a development environment up and running. A modern, complex application probably uses a number of external dependencies, like various database servers, message queue daemons and whatnot. Installing these on every developer's machine individually for a local development environment can be quite a hassle. Using a virtual machine image, you can distribute a pre-configured environment easily.
This does not mean that you set this image up once and cross your fingers that it'll never corrupt. It also doesn't mean that developers are writing their code inside the virtual machine. To create the virtual machine, you should create scripts which can set up a base OS to the desired state. Look at Ansible, Chef, Puppet, simple shell scripts and similar tools for that. These scripts can be used to set up a virtual machine, your production system, test systems etc all from the same source. Creating and distributing a complete image of a virtual machine is just a time saver, since such scripts could take a while to run. It also allows you to easily reset your environment to a known good state if you have messed things up. The VM image is not your one and only source though; if it corrupts it doesn't matter, since it doesn't hold any data or code and since you can simply recreate it.
Secondly, vagrant maps paths inside the virtual machine to paths on the host machine. Your developers can simply write their code as usual on their regular machine and just execute it inside the VM. Since the paths are shared this can happen immediately without needing to copy any files back and forth.
- Maybe vagrant can be useful to you, if your app requires a complex setup.
- Not really, since nothing much changes.
- See above.