13 ms·
Things I Wish I'd Known Before Using Vagrant
- grabcocque 9y agoVagrant's documentation leaves something to be desired. It's perfectly possible to control many VMs from one Vagrantfile, but good luck figuring out how from the docs. I mean with a bit of ruby knowhow and some digging you can figure most stuff out, but Vagrant's documentation still lags behind Hashicorp's other stuff which is usually very well documented.
- zwischenzug 9y agoYeah, that's been my experience too. Which is a shame, as it's an incredibly powerful tool, it just lacks the 'last mile' stuff that Docker did so well.
- waibelp 9y agoThank you for "vagrant global-status". There's still a lot of boxes I don't even remember.
- zwischenzug 9y agoYou're welcome!
- glenscott1 9y agoIf you work with other developers and store your Vagrantfile in source control, then you can allow per-developer settings using the method shown here: https://www.glenscott.co.uk/blog/allow-per-developer-vagrantfile-customisations/ https://www.glenscott.co.uk/blog/allow-per-developer-vagrant...
- stephenr 9y agoI prefer this method: https://gist.github.com/stephenreay/2afd4205e76836f20e17672238a10957 https://gist.github.com/stephenreay/2afd4205e76836f20e176722... Same basic idea but plain ruby constants no need for yaml parsing.
- therealmarv 9y agoI wished I'd known that Vagrant + Windows is always full of surprises. So many problems with Windows developers because Vagrant will not work as expected there :( Anybody know any best practices what to do with Windows developers? I'm thinking of going to docker... but I'm not sure if this really helps.
- zlalanne 9y agoAgreed, symlinks and file permissions always seem to bite the people working on Windows. There are parts of our build process that people working on Windows simply can't run because symlinks are created and VirtualBox/Windows complain.
- throwanem 9y ago> Anybody know any best practices what to do with Windows developers? I always just run a Linux VM and do most things there, with host directories cross-mounted via Cygwin sshd and sshfs (faster, more reliable, and better permissions mapping in my experience than Virtualbox shared folders) and anything that needs to take advantage of filesystem capabilities not supported in NTFS, such as the symlinks mentioned in a sibling comment, done outside a mounted directory. This lets me get work done, but it's a suboptimal experience to say the least, and relies heavily on my prior systems administration experience to stay working when it goes weird. Absent such experience among your developers or at least someone you can put in support of them, about the best I can recommend is to struggle through with Vagrant and your local handful of best practices - at least with Vagrant your dev environments are reproducible, so that when things go too cattywampus you can just burn down the VM and pop a fresh one out of the oven and get back to work. (If your Vagrant boxes aren't reproducible, that's the first thing you want to fix.) Docker for Windows is not going to be an improvement here; on the one hand, it's newer and less battle-hardened, and on the other, it has to run in a VM anyway. (Either Hyper-V or VirtualBox, each of which has its own idiosyncrasies, and only one of which can be used at a time - enable Hyper-V, VirtualBox doesn't work any more.) Docker for Windows, like Docker for Mac, comes with some plumbing that tries to smooth over the impedance mismatch between platforms, but it's lossy and brings its own headaches, so you're just adding more complexity to the dev env for no real gain - you can just run Docker in your Vagrant boxes, if you actually need Docker, and have one fewer headache that way.
- tonetheman 9y agoYup yup this is a good list. Thanks for mentioning landrush, it is something I could have used.
- corford 9y agoOne thing thing I can add to this that was driving me nuts (though not strictly Vagrant's fault): The DHCP client on Ubuntu 16.04LTS doesn't always play nice with multi NIC vagrant machines. All my vagrant boxes are dual NIC (eth0 is the standard 10.0.2.x NAT interface and eth1 is a private interface in the 192.168.56.x range with a static IP - which makes it easier for various vagrant machines to talk directly to each other). I had an infuriating issue where my boxes would startup and then randomly (it seemed at the time) stop responding to network requests. Initially I thought they were hanging for some reason and would tear them down and re-init them. Finally thought to enable GUI mode and I noticed that even though a box had stopped responding, I could login fine via the virtual box GUI. It turned out that Ubuntu's DHCP client was ignoring /etc/network/interfaces (auto generated by vagrant) and wrongly refreshing IP leases on both interfaces (eth0 and eth1). The trick is to kill the running dhclient during provisioning and restart it with switches that force it to only maintain leases for eth0: machine.vm.provision "shell", inline: "kill $(pidof dhclient) && /sbin/dhclient -1 -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases -I -df /var/lib/dhcp/dhclient6.eth0.leases eth0"
- corford 9y agoOh yeah, two other handy networking related commands I use are: vb.customize ["modifyvm", :id, "--macaddress1", "auto"] Which forces a fresh MAC address. vb.customize ["modifyvm", :id, "--nictype1", "Am79C970A"] Which changes the virtual NIC type (for whatever reason, I find on my current host Am79C970A gives much better transfer speeds than virtio)
- throwanem 9y agoThat's not even a little bit Vagrant's fault - that's 100% Ubuntu nonsense, the sort of thing that convinced me about a decade ago never to install Ubuntu again. Sure, running Debian means if you want the latest and greatest you might have to build it yourself. But it's also much less likely to hose you for stupid reasons. I'm glad to see that the state of play has improved so much in the intervening years!
- corford 9y ago
- mister_mister 9y agoFor me vagrant works best with declarative configuration and a runner. something like this, with sane defaults and many options available by changing fields in a dictionary. https://github.com/Attumm/vagrantfile_example/blob/master/Vagrantfile https://github.com/Attumm/vagrantfile_example/blob/master/Va...
- msielski 9y agoAlso big fan of vagrant global-status. I have it aliased to vgs in my terminal. Also very helpful for those using Vagrant on OSX is Vagrant Manager [0] which gives you menu-bar integration and a quick interface to turn VMs on and off. It's useful even to remind myself when I've left some VMs on, especially if I'm running on battery. [0] http://vagrantmanager.com/ http://vagrantmanager.com/
- bryanlarsen 9y ago11. Virtual Box sucks. Try out alternatives, I like vagrant-lxc.
- stephenr 9y agoThis is being unfairly downvoted. I don't use a Linux host so I haven't played with the lxc provider yet but vbox most assuredly does "suck" compared to even the commercial hyper visor alternatives.
- lolsal 9y agoIt's being down-voted because it's a low-effort comment that provides criticism and opinion without any substance or real information and does not contribute to the discussion in a meaningful way.
- pmoriarty 9y agoCould you elaborate on why you think VirtualBox sucks? Or why you think vagrant-lxc is better?
- bryanlarsen 9y agoVirtualBox is slow (especially sharing files), we've had lots of problems with it becoming corrupted, and requiring a fixed partition of RAM makes it very hard to run more than one VM without starving your VM's or host of memory. vagrant-lxc has none of the above problems, it is just containerization with no virtualization penalties. I've had lots of people tell me that Vagrant sucks. When digging into their problems it's almost always been VirtualBox causing their problems.
- scrollaway 9y agoHere's what I wish I'd known before using Vagrant: 1. How to properly do cross-platform, high-performance two-way synced folders between host and guest. Most providers only support one-way syncing. Virtualbox has shared folders, but their performance is pretty lousy and they have issues with relative symlinks. In fact, I still don't fully know what the correct setup is for a dev environment where the files are edited on the host and the guest immediately picks up on them... 2. This idea that with vagrant you'll never again say "It works on my machine" is a lie. So many inconsistencies between Vagrant on Windows, Linux and macOS. Internet connection sharing, line endings issues, symlinking issues, ... If anyone wants to see how we're using Vagrant: https://github.com/hearthsim/hearthsim-vagrant https://github.com/hearthsim/hearthsim-vagrant I don't want to make it sound like Vagrant isn't solving a real problem though, it is. It's just not the unicorn it claims to be.
- throwanem 9y agoI've had much better results mounting host directories via sshfs than I ever have with shared folders. Cygwin sshd works on Windows; there are probably faster ones, but I've never felt the need to bother.
- scrollaway 9y agoI've been meaning to look into vagrant-sshfs but the fact it requires extra setup (quite a bit of it on Windows) has put me off. Our vagrant setup right now is "Install Vagrant, Virtualbox, run this one command and you're done".
- brandonwamboldt 9y agoWe get around the shared folder performance problem using NFS. Adds one extra step to setup (mount a network share), but we've never had performance issues with it.
- ishtu 9y agoDepends on case, for me NFS performance (MacOS as host, Linux as guest) is a major PITA and source of instability in vagrant dev setup.
- ratsimihah 9y agoWow I read "Ten Things I Wish I'd Known Before Using Viagra"
- marksellers 9y agoI've done development with all the databases, languages and packages installed on the host machine, as well as with vagrant. With the VM, I have to ssh in, or switch windows to run tests, whereas before I could just run the tests in vim. How do people achieve fluency with these? I suppose I could install some more of my tools on the VM, but if you take that to its absurd conclusion, I'm just running a clone of my host on the VM. It seems more useful, maybe, to just run databases and other services in the VM. Those are the more difficult bits to manage usually. A good programming language already has version and package management facilities. Or perhaps am I missing something? Anyone have another workflow?
- jcollin 9y agoWe don't use Vagrant, but we use VMs. The workflow is a little bit more convoluted than directly on the host, but we get the benefits of having a consistent way to create environments that are closer - if not identical - to what our customers have. In essence, we do most of our development on Windows, but deploy our solution on Linux. For databases, our former development environment relied on Windows drivers that didn't have the same bugs than the Linux implementations. Hence, we caught these bugs much later in the development phase. Another advantage is that we can deploy different releases of our solution simultaneously. Of course, the cost to get there was to define a new pipeline to build artefacts that we ship on the boxes, but that was a little price to pay.
- zwischenzug 9y agoI have automated from-scratch builds for cluster setups, eg: https://github.com/ianmiell/shutit-openshift-cluster https://github.com/ianmiell/shutit-openshift-cluster https://github.com/ianmiell/shutit-chef-env https://github.com/ianmiell/shutit-chef-env I'll be blogging about some of these soon as well
- pault 9y agoI have never been able to find a performant way to mount host files on a VM, so I just use a headless Ubuntu running in VMware as my dev environment. File mounting in docker containers doesn't have the same speed penalty on a Linux host as it does on win/Mac. I use tmux and vim. I've been using this setup happily for years now.
- wildpeaks 9y agoA couple more for the list: 11. Shared folders get setup before provision scripts are run 12. You can detect provision has already run (https://github.com/hashicorp/vagrant/issues/936#issuecomment-288063253 https://github.com/hashicorp/vagrant/issues/936#issuecomment...) using: if File.exist?(".vagrant/machines/YOUR_BOX_ID/virtualbox/action_provision") 13. Vagrantfile configs are actually Ruby scripts, so you could do things like storing your box configs in JSON (like I did in https://github.com/wildpeaks/boilerplate-vagrant-xenial64 https://github.com/wildpeaks/boilerplate-vagrant-xenial64 ) instead of hardcoding them in the Vagrantfile. 14. Virtualbox needs Hyper-V disabled whereas Docker for Windows requires Hyper-V enabled.
- stephenr 9y agoFor 14 - just use a hyperv as your provider with Vagrant. You'll probably get better synced folder performance as a bonus.
- zwischenzug 9y agoI like 13).
- djsumdog 9y ago> Vagrantfile configs are actually Ruby scripts I took advantage of this by storing all my settings in YAML and then using the same YAML for both Vagrant and my Ansible provisioner: Here's the Ruby Script that loads the YAML: https://github.com/BigSense/vSense/blob/master/core/vagrantenv.rb https://github.com/BigSense/vSense/blob/master/core/vagrante... That I call from my Vagrant file: https://github.com/BigSense/vSense/blob/master/core/infrastructure/Vagrantfile https://github.com/BigSense/vSense/blob/master/core/infrastr... That is also loaded in all my Ansible roles: https://github.com/BigSense/vSense/blob/master/ansible/bigsense.yml https://github.com/BigSense/vSense/blob/master/ansible/bigse...
- invisiblea 9y ago- Vagrant Triggers plugin is super useful https://github.com/emyl/vagrant-triggers https://github.com/emyl/vagrant-triggers - I've found VMware Fusion as a provider worth the extra cost/disk space
- stephenr 9y agoDo you find vmware base box availability an issue? Is it just you or a team using VMware?
- invisiblea 9y agoThere's between two and five of us, and we use the puphpet/ubuntu1604-x64 box. https://app.vagrantup.com/puppetlabs/boxes/ubuntu-16.04-64-puppet https://app.vagrantup.com/puppetlabs/boxes/ubuntu-16.04-64-p... Also here's a template for an initial LEMP WP setup https://github.com/alexwybraniec/bwu-vagrant-wordpress https://github.com/alexwybraniec/bwu-vagrant-wordpress
- mafro 9y agoCreating your own base boxes is actually pretty straight forward since Packer. Maintaining them is admittedly a bit of a time sink though.
- stephenr 9y agoHaha I'm aware. I'm the maintainer for https://app.vagrantup.com/koalephant https://app.vagrantup.com/koalephant - I was curious about vmware+Vagrant usage, we don't support it right now but I'm considering adding it.
- invisiblea 9y agoOh and while it is in the docs, the sendfile/virtualbox gotcha has been the cause of many hours of anger https://www.vagrantup.com/docs/synced-folders/virtualbox.html https://www.vagrantup.com/docs/synced-folders/virtualbox.htm...
- damagednoob 9y agoI've used Vagrant extensively in the past but since I found docker-compose, I haven't reached for it over the past year.
- mafro 9y agoDocker and Vagrant are two very different tools.
- welly 9y agoAre they? Very different? Not really.
- Can_Not 9y agoI'm pretty fustrated reading comments like these because there are use-cases where these tools are pretty much the same and use-cases where these tools are wildly different and you guys are going back and forth arguing semantics that are totally meaningless without the context or use case.
- ahnick 9y agoI think the parent's point is that for the majority of web development use cases (which I'd wager was a large percentage of the Vagrant user base) Docker has eliminated the need for Vagrant. Agreed, though that there are times when you need to simulate software running on a particular machine and for that Vagrant is still useful.
- welly 9y agoOf course there are use-cases for these tools where they can be applied to wildly different requirements but in essence they're not "very different tools", they're very similar in more ways than not.
- pasta 9y agoOfcourse this depends on the kind of project, but my last experience with a big Laravel project was that I was running the project working under Apache on my local machine and the rest of the team was loosing a lot of time because Vagrant was not working as expected. I can understand the need for reproducible environments. But when so much time is lost I doubt the first thing you need is something like Vagrant. To me Vagrant is a tool that you use when the team starts to struggle with "works on my machine". But not before that. Because most of the time (well for PHP at least) it's very easy to make it work on all machines.
- pivotal 9y agoI've had quite the opposite experience. Vagrant has saved my team lots of time fighting environmental issues. The approach of running apache locally falls apart pretty quickly as you add more components to your application. Elastic search, mongo, one person happens to have php 7 instead of 5.2 and wrote everything with short array syntax, etc. We also work on many different projects, often getting dropped into something new without much of a primer. Being able to "vagrant up" and not having to know all the dependencies to get up and running is very handy. Do we spend time troubleshooting vagrant weirdness? For sure, but compared to the time saved it's a no-brainer.
- samsonradu 9y agoI tend to agree with the parent comment, a small team can get away without it if the software stack is stable. PHP 5.2 to 7 is quite a change and should have been documented upfront. I assume that the project must conform to certain software requirements. On the other hand, npm is full of surprises.
- pivotal 9y agoI don't disagree that if you can get away with just a local development environment that it is likely easier to get up and running. However, it requires good documentation of project dependencies and discipline by the team to not accidentally upgrade their version of PHP without telling anyone, both things that are easier said than done. Vagrant lets you codify that through "code". In the case of my employer, it's a necessity, but obviously everyone is different.
- drinchev 9y agoVagrant's private network is really cool as well. I use it to test ansible provisioning scripts for server infrastructure. config.vm.define "ums-01" do |machine| machine.vm.network "private_network", ip: "192.168.1.10" machine.vm.network :forwarded_port, guest: 22, host: 2210, id: "ssh" end config.vm.define "ums-02" do |machine| machine.vm.network "private_network", ip: "192.168.1.20" machine.vm.network :forwarded_port, guest: 22, host: 2220, id: "ssh" end -- https://www.vagrantup.com/docs/networking/private_network.html https://www.vagrantup.com/docs/networking/private_network.ht...
- jeff_vader 9y agoMy top tip: install your dotfiles into any Vagrant VM without modifying anything in the VMs Vagrantfile/provisioning scripts: https://gist.github.com/tadas-s/0cd468a4cc9fa4cafce6fe57a5dce123 https://gist.github.com/tadas-s/0cd468a4cc9fa4cafce6fe57a5dc...
- stephenr 9y agoBecause you said "without modifying anything in the vms Vagrantfile" I assume you put this in $VAGRANT_HOME/Vagrantfile? Also, nice username. You'll need a tray.
- jeff_vader 9y agoNo, you put that Vagrantfile with provisioner installing your dotfiles into $HOME/.vagrant.d/ folder. Every time vagrant creates or starts any vm it will sort of "extend" its configuration by reading $HOME/.vagrant.d/Vagrantfile (if it exists).
- stephenr 9y agoUm yeah. That's the default location for $VAGRANT_HOME if you don't set the env var.
- nicolasbistolfi 9y agoFore me something that inclined me to use vagrant, was the share feature, so I can let anyone in the world check my development environment. Now they deprecated that feature and https://ngrok.com https://ngrok.com does the job very well.
- bauerd 9y agoI was a long-time Vagrant user but recently switched almost completely to Docker (Compose). What features does Docker miss that make people keep using Vagrant?
- Willson50 9y agoSnapshots are pretty useful, I miss those.
- cosarara97 9y agoVagrant gives you a full VM with a traditional init system. Docker is usually used without an init (or a very dumb init), so you'll have different containers for each service. It's a very different way of working, and I'd argue vagrant's is simpler and easier to understand, but less scalable.
- bauerd 9y agoYeah I understand the difference between the two but I was wondering why people prefer Vagrant over Docker for development environments.
- mitchty 9y agoFor me, because docker doesn't do jack to help with developing in the kernel.
- dominotw 9y agoI think this is one of the edge cases where vagrant is useful over docker. Most ppl here don't do kernel dev though.
- pizza234 9y agoAt my company we need to have virtual machines as close as possible (software wise) to our production environment, including the kernel version.
- 9y ago
- cczomps 9y agoHello everyone,i would like to a help a friend who helped me get out of a dysfunctional and abusive relationship and helped me get proof of infidelity from my ex husband's devices.If you have a similar problem or you need to hack any device or website and you require 100% guarantee and anonymity, reach out to this computer guru via email with BLACKSPOTHACK @ GMAIL DOT COM
- mitchty 9y agoHere's my advice go to GitHub and type: filename:Vagrantfile thing you're looking for You'd be suprised how many hidden gems are on GitHub that you can use to figure out how to use vagrant. This tip applies more generally.
- amorphid 9y agoI often find Google searches for GitHub gists to be super useful. <stuff you care about> Vagrantfile site:gist.github.com
- achiang 9y agoWe've avoided many of the problems (and solutions) in the link by standardizing on Ubuntu laptops for the host OS, and using vagrant-lxc to run our vagrant guests. https://github.com/fgrehm/vagrant-lxc https://github.com/fgrehm/vagrant-lxc At least one or two of our new hires started with OSX hosts, but switched to Ubuntu after a while, to avoid virtualbox pain. [edit: added vagrant-lxc link]
- cwaffler 9y agoI highly recommend lando. Basically an easy to use CLI wrapper for docker apps. https://docs.devwithlando.io/ https://docs.devwithlando.io/
- ahnick 9y agoFrom a development perspective, what's the advantage here over just using Docker Compose? Is it the baked in recipes that it provides?
- deleted 9y ago[deleted]
- conradfr 9y agoIf you're a PHP dev (or even not) check https://puphpet.com/ https://puphpet.com/ I generate my Vagrant files for all my side projects with it and it's a real time saver, especially if you're not savvy in those fancy provisioners or sysadmin in general.
- wkral 9y agoI'd advise caution with the use of landrush, at my company it was very quick to get up and running using it, but we encountered several problems with it over time. We have several vagrant boxes coming up and down at various times on each developer's machine and it would tend to get out of sync in various cases, hold on to records for machines that no longer existed and macOS DNS cache also played a role. Eventually we replaced it with Dnsmasq and a static IP setup with each development box getting an immutable static IP. Dnsmasq runs on a guest VM that needs to always be up for other purposes as well. As always the effort from the landrush developers is much appreciated and it may be suitable for a limited number of boxes but it didn't scale with our usecase.
- jeffshek 9y agoAnother thing to add to the list is you can set Paravirtualization Interface if you're using VirtualBox. If your defaults are currently on "Legacy", empirically we saw 10-30% speedup by switching to "KVM".
- pmontra 9y agoThere used to be a problem with running Vagrant on VirtualBox with more than 1 CPU: https://github.com/rdsubhas/vagrant-faster/issues/5 https://github.com/rdsubhas/vagrant-faster/issues/5 Explanation and workarounds: http://www.mihaimatei.com/virtualbox-performance-issues-multiple-cpu-cores/ http://www.mihaimatei.com/virtualbox-performance-issues-mult... Did they fix this?
- vlunkr 9y agoAdding swap really is critical. Machines running out of swap was causing my MBP to crash ~once a day, enough that I ran linux on it for a while (it was more stable for whatever reason) until we figured out what the issue was.
- ironjunkie 9y agoIs anyone really using Vagrant for anything more than quick tasks on your local dev machines? I always perceived Vagrant as a hack.
- ridiculous_fish 9y agoI use Vagrant to let me test on multiple Linux and BSD distros. The large number of available boxes makes this easy.
- raziel2p 9y agoWhat would you do instead if you want to test things that need to run on actual VMs? Configuration management or whatever. Is booting a VM at a public cloud provider any less of a hack?
- vultour 9y agoLast time I did this I just created a base VM that had Ansible set up and anytime you wanted to get the latest environment you just ran a script. Although I admit that I'm sort of an infrastructure fanatic and love Ansible, so that might be why I steer away from things like Vagrant.
- stephenr 9y agoIt's a ruby app to standardise configuring and provisioning VMs on any one of a number of hypervisor/container platforms. How would you provide reproducible dev environments?
- ironjunkie 9y agoVagrant is definitely wonderful to quickly provision VMs across multiple hypervisors, but that's where I also see it as a hack. It will not always replicate exactly what you need on each hypervisor, and so many times you will end up with something not working (example: synced folders with host). I have always managed my VMs directly in KVM. Takes more time but I don't rely on a middle-layer//wrapper.
- zimbatm 9y agoAnother thing that's good to know: vboxfs (the default VirtualBox file-sharing filesystem) doesn't support mmap(). The are quite a few software that use mmap to access files, especially databases. When that happens, either avoid using the shared folder or switch to using the nfs mount. Here is the ticket about it that's been opened 10 years ago: https://www.virtualbox.org/ticket/819 https://www.virtualbox.org/ticket/819