hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.32k stars 4.43k forks source link

Docker Provisioner takes 9+ minutes to install docker #7161

Closed darkn3rd closed 4 years ago

darkn3rd commented 8 years ago

Vagrant version

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.provision "docker"
end

Debug output

https://gist.github.com/darkn3rd/775f9b496f3d80d57ba3

# from the gist
[ -x /usr/bin/lsb_release ] && /usr/bin/lsb_release -i 2>/dev/null | grep Ubuntu
sudo test -f /usr/bin/docker
sudo test -f /usr/local/bin/docker
sudo test -f /usr/sbin/docker
sudo apt-get update -qq -y                             # 1m39
sudo apt-get install -qq -y --force-yes curl apt-transport-https
sudo apt-get purge -qq -y lxc-docker* || true
curl -sSL https://get.docker.com/ | sudo sh            # 8m21.600s
test -f /usr/bin/docker
getent group docker
id -Gn | grep docker
sudo usermod -a -G docker vagrant
test -f /var/run/docker.pid
test -f /var/run/docker.pid

Expected behavior

Expecting that using vagrant's docker provisioner would take around two minutes. I looked through the debug output, and it seems the curl command takes a lot of time, about 8 minutes. Using steps documented from Docker Ubuntu Install, the install takes 2m12.201s:

apt-get update                                        # 0m29.270s
apt-get install apt-transport-https ca-certificates   # 0m0.392s
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D # 0m0.652s
echo 'deb https://apt.dockerproject.org/repo ubuntu-trusty main' > /etc/apt/sources.list.d/docker.list
apt-get update                                        # 0m6.792s
apt-get purge lxc-docker                              # 0m0.351s
apt-get install linux-image-extra-$(uname -r)         # 0m54.865s
apt-get install apparmor                              # 0m0.339s
apt-get update                                        # 0m12.315s
apt-get install -y docker-engine                      # 0m12.310s
usermod -a -G docker vagrant
service docker start                                  # 0m0.011s

Actual behavior

Vagrant provision takes unusually long time. Sometimes between 9 minutes and 18 minutes, which is too slow to be usable.

$ time vagrant provision
==> default: Running provisioner: docker...
    default: Installing Docker onto machine...

real    9m25.384s
user    0m2.429s
sys 0m0.620s

Steps to reproduce

  1. vagrant up --no-provision
  2. vagrant provision
sethvargo commented 8 years ago

This looks similar to https://github.com/mitchellh/vagrant/issues/5319.

I think there's something different about how Vagrant is invoking curl in the subprocess that is slowing it down /cc @mitchellh

darkn3rd commented 8 years ago

This may explain why I get the 18+ minute zone. The curl command run manually from within a vagrant box takes 8 minutes alone, so I don't know if it is a combination of these two factors, or they are the same thing.

chippawah commented 8 years ago

+1 to this issue. I'm new to Vagrant and Docker, the hang time on install is brutal when I'm iterating over many different configurations. Unlikely to use either tech if it's so slow all the time.

jar349 commented 8 years ago

+1 also happening to me. Same environment/versions - expect host is Linux Mint, not OS X.

jetbasrawi commented 8 years ago

+1 Same issue for me. Have we got a solution yet?

skirdey commented 8 years ago

+1 Same here, Vagrant 1.8.1 Virtual Box 5.0.20

akutz commented 8 years ago

+1 Vagrant 1.8.1 Virtual Box 5.0.20

jchinkle commented 8 years ago

Having this same issue as well.

Vagrant 1.8.1 VB 5.0.20

sijpkes commented 8 years ago

Me too +1

Vagrant 1.8.5 VB 5.0.26 r108824

joyfulmonster commented 8 years ago

Vagrant 1.8.5 VB 5.0.26 r108824

sijpkes commented 8 years ago

I'm wondering if this should even be a bug since, now that I know more about Docker, running it inside a VM seems superfluous. I worked around this by just running Docker on my Desktop.

ardeearam commented 8 years ago

+1

Vagrant 1.8.1 VB 5.0.24_Ubuntu r108355

muhammadghazali commented 7 years ago

+1

Vagrant 1.8.6 VirtualBox 4.3.36_Ubuntu r105129

muhammadghazali commented 7 years ago

The alternative is using garethr-docker puppet module to install the docker engine and pulling docker images. I was able to reduce the provisioning time...

ghost commented 7 years ago

+1

I'm experiencing the same issue.

Vagrant version: 1.9.1 VirtualBox version: VirtualBox-5.0.30-112061-Win Host computer OS: Windows 7

voskobovich commented 7 years ago

+1

Vagrant version: 1.9.1 VirtualBox version: 5.0.30 r112061 Host OS: macOS Sierra (10.12.3)

nicknezis commented 7 years ago

Are you guys using the new native OSX Docker? If you use the "d.force_host_vm = false" parameter you can skip the step of Vagrant installing and running a VM to run docker within. Here is a Gist showing how I'm using it. https://gist.github.com/nicknezis/fd5845251a8805729cd05bfca5680a15

Also here is the link to Docker for Mac: https://docs.docker.com/docker-for-mac/

jamiejackson commented 7 years ago

@muhammadghazali

The alternative is using garethr-docker puppet module to install the docker engine and pulling docker images. I was able to reduce the provisioning time...

Could you share how you implemented it? I have only used shell provisioners--I haven't used Puppet.

mcandre commented 7 years ago

I'm wondering if this should even be a bug since, now that I know more about Docker, running it inside a VM seems superfluous. I worked around this by just running Docker on my Desktop.

@sijpkes For the majority of Docker users among the Linux, macOS, and Windows crowd, yes, Docker ideallys runs "natively" from the host without any additional Vagrant virtualization bogging things down. And yet there are likely some Docker users who, for whatever reason, want to run Docker on even stranger hosts--BSD, Haiku, Solaris, and so on, where Docker may not be easy to obtain, and so some sort of VM for a Docker-friendly guest may be more convenient in the short term, while waiting for Docker support to come to their poison ahem OS of choice.

darkn3rd commented 6 years ago

Context: At the time this was written, docker in xhyve (docker-for-mac) or hyper-v (docker-for-win) were new, and docker-machine with virtualbox provider was still popular. Vagrant was an alternative to docker-machine, but it was slow, as the download.

It seems newer version of vagrant will just use native docker (or docker in hyper-v on win or hyperkit on mac via docker-for-win and docker-for-mac), as config.vm.provider("docker") { |dkr| dkr.force_host_vm = false } is false by default. So this would need to be set to true to reproduce on Win/Mac/Lin.

For using alternative tool or process, e.g. puppet, ansible, etc., is not the scope of the bug, as the bug is the vagrant provisioner, when it needs to fetch docker and install in the vm, it takes abnormally long time.

chrisroberts commented 4 years ago

Hi there,

It looks like this has been resolved within a previously shipped version of Vagrant so I am now closing this issue. If the original issue was not fully resolved, please reopen this issue or create a new one.

Cheers!

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.