LoginSignup
17
16

More than 5 years have passed since last update.

[Vagrant] 「CentOSのboxでbundle installやgem installが異常に遅い」問題を解決する方法

Posted at

Vagrantの仮想マシン上でbundle installが遅い。
Bundlerの問題というより、ネットワークの遅延の問題に見える。

[vagrant@localhost ~]$ time sh -c 'curl www.rubygems.org:443 > /dev/null'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
132   264  132   264    0     0     49      0  0:00:05  0:00:05 --:--:--  2256
real    0m5.340s
user    0m0.000s
sys 0m0.006s
[vagrant@localhost ~]$ time sh -c 'curl www.rubygems.org:80 > /dev/null'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:05 --:--:--     0
real    0m5.268s
user    0m0.000s
sys 0m0.005s

この問題はVagrantはじめ各所で報告されていて、Vagrant向けのCentOS boxの設定が原因らしい。

具体的には、CentOSがVirtualBoxのNAT DNS Proxy(10.0.2.3)を読みにいくように設定されていると、名前解決が異常に遅くなる、というのが根本原因。
VagrantでVirtualBox Providerを利用していて、NAT DNS Proxyを使うような設定がされているboxを使っていた場合、名前解決に時間がかかるためにbundle installやgem installが異常に遅い、という結果になる。

対策としては、以下のようにVirtualBox Providerを設定することでNAT DNS Proxyを無効化すれば、ホストOSのネットワークから/etc/resolv.confの設定を自動判別するようになり、結果的に解決する。

config.vm.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
config.vm.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
17
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
16