项目作者: zoobab

项目描述 :
vagrant-inside-docker
高级语言: Dockerfile
项目地址: git://github.com/zoobab/vagrant-inside-docker.git
创建时间: 2017-02-11T17:25:18Z
项目社区:https://github.com/zoobab/vagrant-inside-docker

开源协议:GNU General Public License v3.0

下载


noswpatv3

About

Running vagrant inside a docker container. We use a small box based on OpenWRT 15.05 as a lightweight distro (7MB).

Requirements

You need vagrant kernel modules on the host.

But why?

To quote the FOSDEM2017 presentation on “Running virtual machines in containers”:

https://fosdem.org/2017/schedule/event/virtcontainers/

  1. The idea of running virtual machines inside containers is surprisingly old and
  2. was used due to several reasons. They include willingness to run VM-s in
  3. container orchestration engines like Kubernetes or Borg, or packaging IaaS
  4. cloud software like OpenStack in containers. In this presentation, I am going
  5. to describe these use cases and two main different approaches of containerizing
  6. VM-s - putting every qemu(-kvm) process in a separate container (like Borg or
  7. Rancher OS are doing) and putting libvirtd process in container (like OpenStack
  8. Kolla or Stackanetes are doing)

Usage

Just launch ./run.sh

Oneliner

You can also run it as a oneliner:

  1. docker run --privileged -v /dev/vboxdrv:/dev/vboxdrv -v /dev/vboxnetctl:/dev/vboxnetctl -it zoobab/vagrant-inside-docker:latest /bin/bash -c "vagrant up && vagrant ssh"

Screenshot

Everybody love screenshots:

Vagrant running inside a Docker container with OpenWRT as small distro

  1. zoobab@filez /home/zoobab/vagrant-inside-docker [33]$ ./run.sh
  2. Bringing machine 'default' up with 'virtualbox' provider...
  3. ==> default: Importing base box 'living42/openwrt-15.05-x86'...
  4. ==> default: Matching MAC address for NAT networking...
  5. ==> default: Checking if box 'living42/openwrt-15.05-x86' is up to date...
  6. ==> default: Setting the name of the VM: vagrant-openwrt_default_1487750817274_66403
  7. ==> default: Clearing any previously set network interfaces...
  8. ==> default: Preparing network interfaces based on configuration...
  9. default: Adapter 1: nat
  10. ==> default: Forwarding ports...
  11. default: 80 (guest) => 8081 (host) (adapter 1)
  12. default: 22 (guest) => 2222 (host) (adapter 1)
  13. ==> default: Running 'pre-boot' VM customizations...
  14. ==> default: Booting VM...
  15. ==> default: Waiting for machine to boot. This may take a few minutes...
  16. default: SSH address: 127.0.0.1:2222
  17. default: SSH username: vagrant
  18. default: SSH auth method: private key
  19. default:
  20. default: Vagrant insecure key detected. Vagrant will automatically replace
  21. default: this with a newly generated keypair for better security.
  22. default:
  23. default: Inserting generated public key within guest...
  24. default: Removing insecure key from the guest if it's present...
  25. default: Key inserted! Disconnecting and reconnecting using new SSH key...
  26. ==> default: Machine booted and ready!
  27. ==> default: Checking for guest additions in VM...
  28. default: No guest additions were detected on the base box for this VM! Guest
  29. default: additions are required for forwarded ports, shared folders, host only
  30. default: networking, and more. If SSH fails on this machine, please install
  31. default: the guest additions and repackage the box to continue.
  32. default:
  33. default: This is not an error message; everything may continue to work properly,
  34. default: in which case you may ignore this message.
  35. _______ ________ __
  36. | |.-----.-----.-----.| | | |.----.| |_
  37. | - || _ | -__| || | | || _|| _|
  38. |_______|| __|_____|__|__||________||__| |____|
  39. |__| W I R E L E S S F R E E D O M
  40. -----------------------------------------------------
  41. CHAOS CALMER (15.05, r46767)
  42. -----------------------------------------------------
  43. * 1 1/2 oz Gin Shake with a glassful
  44. * 1/4 oz Triple Sec of broken ice and pour
  45. * 3/4 oz Lime Juice unstrained into a goblet.
  46. * 1 1/2 oz Orange Juice
  47. * 1 tsp. Grenadine Syrup
  48. -----------------------------------------------------
  49. vagrant@OpenWrt:~$

Bugs

  • Sometimes docker stop takes time to stop the running container, or never stops it :-)
  • Sometimes virtualbox of the GUEST container is very sensitive to the version
    of the HOST, so the closer they are the better.
  • I had to upgrade and do some debian pinning to have virtualbox and vagrant
    from Ubuntu Zesty while the rest of the distro was still on Xenial. Will
    provide a pinning example once I have it working.

Links