TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Things I Wish I'd Known Before Using Vagrant

304 点作者 zwischenzug超过 7 年前

29 条评论

scrollaway超过 7 年前
Here&#x27;s what I wish I&#x27;d known before using Vagrant:<p>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&#x27;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...<p>2. This idea that with vagrant you&#x27;ll never again say &quot;It works on my machine&quot; is a lie. So many inconsistencies between Vagrant on Windows, Linux and macOS. Internet connection sharing, line endings issues, symlinking issues, ...<p>If anyone wants to see how we&#x27;re using Vagrant:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;hearthsim&#x2F;hearthsim-vagrant" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;hearthsim&#x2F;hearthsim-vagrant</a><p>I don&#x27;t want to make it sound like Vagrant isn&#x27;t solving a real problem though, it is. It&#x27;s just not the unicorn it claims to be.
评论 #15569530 未加载
评论 #15571722 未加载
评论 #15567885 未加载
评论 #15567417 未加载
评论 #15571749 未加载
评论 #15568012 未加载
评论 #15568034 未加载
评论 #15570879 未加载
评论 #15575556 未加载
评论 #15567593 未加载
评论 #15569294 未加载
wildpeaks超过 7 年前
A couple more for the list:<p>11. Shared folders get setup before provision scripts are run<p>12. You can detect provision has already run (<a href="https:&#x2F;&#x2F;github.com&#x2F;hashicorp&#x2F;vagrant&#x2F;issues&#x2F;936#issuecomment-288063253" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;hashicorp&#x2F;vagrant&#x2F;issues&#x2F;936#issuecomment...</a>) using:<p><pre><code> if File.exist?(&quot;.vagrant&#x2F;machines&#x2F;YOUR_BOX_ID&#x2F;virtualbox&#x2F;action_provision&quot;) </code></pre> 13. Vagrantfile configs are actually Ruby scripts, so you could do things like storing your box configs in JSON (like I did in <a href="https:&#x2F;&#x2F;github.com&#x2F;wildpeaks&#x2F;boilerplate-vagrant-xenial64" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;wildpeaks&#x2F;boilerplate-vagrant-xenial64</a> ) instead of hardcoding them in the Vagrantfile.<p>14. Virtualbox needs Hyper-V disabled whereas Docker for Windows requires Hyper-V enabled.
评论 #15568753 未加载
评论 #15567989 未加载
评论 #15567619 未加载
corford超过 7 年前
One thing thing I can add to this that was driving me nuts (though not strictly Vagrant&#x27;s fault):<p>The DHCP client on Ubuntu 16.04LTS doesn&#x27;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).<p>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.<p>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.<p>It turned out that Ubuntu&#x27;s DHCP client was ignoring &#x2F;etc&#x2F;network&#x2F;interfaces (auto generated by vagrant) and wrongly refreshing IP leases on both interfaces (eth0 and eth1).<p>The trick is to kill the running dhclient during provisioning and restart it with switches that force it to only maintain leases for eth0:<p><pre><code> machine.vm.provision &quot;shell&quot;, inline: &quot;kill $(pidof dhclient) &amp;&amp; &#x2F;sbin&#x2F;dhclient -1 -v -pf &#x2F;run&#x2F;dhclient.eth0.pid -lf &#x2F;var&#x2F;lib&#x2F;dhcp&#x2F;dhclient.eth0.leases -I -df &#x2F;var&#x2F;lib&#x2F;dhcp&#x2F;dhclient6.eth0.leases eth0&quot;</code></pre>
评论 #15567404 未加载
评论 #15567346 未加载
therealmarv超过 7 年前
I wished I&#x27;d known that Vagrant + Windows is always full of surprises. So many problems with Windows developers because Vagrant will not work as expected there :(<p>Anybody know any best practices what to do with Windows developers? I&#x27;m thinking of going to docker... but I&#x27;m not sure if this really helps.
评论 #15567377 未加载
评论 #15567492 未加载
评论 #15567591 未加载
评论 #15571437 未加载
评论 #15567298 未加载
glenscott1超过 7 年前
If you work with other developers and store your Vagrantfile in source control, then you can allow per-developer settings using the method shown here: <a href="https:&#x2F;&#x2F;www.glenscott.co.uk&#x2F;blog&#x2F;allow-per-developer-vagrantfile-customisations&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.glenscott.co.uk&#x2F;blog&#x2F;allow-per-developer-vagrant...</a>
评论 #15568058 未加载
bauerd超过 7 年前
I 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?
评论 #15569452 未加载
评论 #15568750 未加载
评论 #15568786 未加载
评论 #15568582 未加载
评论 #15571029 未加载
评论 #15569085 未加载
评论 #15569738 未加载
评论 #15568529 未加载
评论 #15568853 未加载
conradfr超过 7 年前
If you&#x27;re a PHP dev (or even not) check <a href="https:&#x2F;&#x2F;puphpet.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;puphpet.com&#x2F;</a><p>I generate my Vagrant files for all my side projects with it and it&#x27;s a real time saver, especially if you&#x27;re not savvy in those fancy provisioners or sysadmin in general.
drinchev超过 7 年前
Vagrant&#x27;s private network is really cool as well. I use it to test ansible provisioning scripts for server infrastructure.<p><pre><code> config.vm.define &quot;ums-01&quot; do |machine| machine.vm.network &quot;private_network&quot;, ip: &quot;192.168.1.10&quot; machine.vm.network :forwarded_port, guest: 22, host: 2210, id: &quot;ssh&quot; end config.vm.define &quot;ums-02&quot; do |machine| machine.vm.network &quot;private_network&quot;, ip: &quot;192.168.1.20&quot; machine.vm.network :forwarded_port, guest: 22, host: 2220, id: &quot;ssh&quot; end </code></pre> -- <a href="https:&#x2F;&#x2F;www.vagrantup.com&#x2F;docs&#x2F;networking&#x2F;private_network.html" rel="nofollow">https:&#x2F;&#x2F;www.vagrantup.com&#x2F;docs&#x2F;networking&#x2F;private_network.ht...</a>
wkral超过 7 年前
I&#x27;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&#x27;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.<p>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.<p>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&#x27;t scale with our usecase.
mitchty超过 7 年前
Here&#x27;s my advice go to GitHub and type:<p>filename:Vagrantfile thing you&#x27;re looking for<p>You&#x27;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.
评论 #15568903 未加载
invisiblea超过 7 年前
- Vagrant Triggers plugin is super useful <a href="https:&#x2F;&#x2F;github.com&#x2F;emyl&#x2F;vagrant-triggers" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;emyl&#x2F;vagrant-triggers</a><p>- I&#x27;ve found VMware Fusion as a provider worth the extra cost&#x2F;disk space
评论 #15568203 未加载
评论 #15568082 未加载
msielski超过 7 年前
Also big fan of vagrant global-status. I have it aliased to vgs in my terminal.<p>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&#x27;s useful even to remind myself when I&#x27;ve left some VMs on, especially if I&#x27;m running on battery.<p>[0] <a href="http:&#x2F;&#x2F;vagrantmanager.com&#x2F;" rel="nofollow">http:&#x2F;&#x2F;vagrantmanager.com&#x2F;</a>
achiang超过 7 年前
We&#x27;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.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;fgrehm&#x2F;vagrant-lxc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;fgrehm&#x2F;vagrant-lxc</a><p>At least one or two of our new hires started with OSX hosts, but switched to Ubuntu after a while, to avoid virtualbox pain.<p>[edit: added vagrant-lxc link]
mister_mister超过 7 年前
For 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.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;Attumm&#x2F;vagrantfile_example&#x2F;blob&#x2F;master&#x2F;Vagrantfile" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Attumm&#x2F;vagrantfile_example&#x2F;blob&#x2F;master&#x2F;Va...</a>
nicolasbistolfi超过 7 年前
Fore 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 <a href="https:&#x2F;&#x2F;ngrok.com" rel="nofollow">https:&#x2F;&#x2F;ngrok.com</a> does the job very well.
pasta超过 7 年前
Ofcourse 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.<p>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 &quot;works on my machine&quot;. But not before that. Because most of the time (well for PHP at least) it&#x27;s very easy to make it work on all machines.
评论 #15567987 未加载
评论 #15568870 未加载
damagednoob超过 7 年前
I&#x27;ve used Vagrant extensively in the past but since I found docker-compose, I haven&#x27;t reached for it over the past year.
评论 #15568631 未加载
jeffshek超过 7 年前
Another thing to add to the list is you can set Paravirtualization Interface if you&#x27;re using VirtualBox.<p>If your defaults are currently on &quot;Legacy&quot;, empirically we saw 10-30% speedup by switching to &quot;KVM&quot;.
pmontra超过 7 年前
There used to be a problem with running Vagrant on VirtualBox with more than 1 CPU: <a href="https:&#x2F;&#x2F;github.com&#x2F;rdsubhas&#x2F;vagrant-faster&#x2F;issues&#x2F;5" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rdsubhas&#x2F;vagrant-faster&#x2F;issues&#x2F;5</a><p>Explanation and workarounds: <a href="http:&#x2F;&#x2F;www.mihaimatei.com&#x2F;virtualbox-performance-issues-multiple-cpu-cores&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.mihaimatei.com&#x2F;virtualbox-performance-issues-mult...</a><p>Did they fix this?
jeff_vader超过 7 年前
My top tip: install your dotfiles into any Vagrant VM without modifying anything in the VMs Vagrantfile&#x2F;provisioning scripts: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;tadas-s&#x2F;0cd468a4cc9fa4cafce6fe57a5dce123" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;tadas-s&#x2F;0cd468a4cc9fa4cafce6fe57a5dc...</a>
评论 #15570507 未加载
bryanlarsen超过 7 年前
11. Virtual Box sucks. Try out alternatives, I like vagrant-lxc.
评论 #15569903 未加载
评论 #15568114 未加载
waibelp超过 7 年前
Thank you for &quot;vagrant global-status&quot;. There&#x27;s still a lot of boxes I don&#x27;t even remember.
评论 #15567251 未加载
marksellers超过 7 年前
I&#x27;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?<p>I suppose I could install some more of my tools on the VM, but if you take that to its absurd conclusion, I&#x27;m just running a clone of my host on the VM.<p>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.<p>Or perhaps am I missing something? Anyone have another workflow?
评论 #15569522 未加载
评论 #15567497 未加载
评论 #15567499 未加载
评论 #15567514 未加载
zimbatm超过 7 年前
Another thing that&#x27;s good to know: vboxfs (the default VirtualBox file-sharing filesystem) doesn&#x27;t support mmap().<p>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.<p>Here is the ticket about it that&#x27;s been opened 10 years ago: <a href="https:&#x2F;&#x2F;www.virtualbox.org&#x2F;ticket&#x2F;819" rel="nofollow">https:&#x2F;&#x2F;www.virtualbox.org&#x2F;ticket&#x2F;819</a>
vlunkr超过 7 年前
Adding 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.
cwaffler超过 7 年前
I highly recommend lando. Basically an easy to use CLI wrapper for docker apps.<p><a href="https:&#x2F;&#x2F;docs.devwithlando.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;docs.devwithlando.io&#x2F;</a>
评论 #15571299 未加载
ironjunkie超过 7 年前
Is anyone really using Vagrant for anything more than quick tasks on your local dev machines? I always perceived Vagrant as a hack.
评论 #15570336 未加载
评论 #15570579 未加载
评论 #15570329 未加载
tonetheman超过 7 年前
Yup yup this is a good list. Thanks for mentioning landrush, it is something I could have used.
grabcocque超过 7 年前
Vagrant&#x27;s documentation leaves something to be desired. It&#x27;s perfectly possible to control many VMs from one Vagrantfile, but good luck figuring out how from the docs.<p>I mean with a bit of ruby knowhow and some digging you can figure most stuff out, but Vagrant&#x27;s documentation still lags behind Hashicorp&#x27;s other stuff which is usually very well documented.
评论 #15567232 未加载