vagrant

vagrantの使い方

タグ vagrant virtualbox libvirt


概要

  • 仮想化ソフトウェアのCLIで統一的に扱えるwrapper
  • バックエンドの仮想化ソフトで利用できるのは以下の通り
    • virtualbox
      • 最もvagrantでサポートされているテンプレートの仮想マシンが多い
    • libvirt
    • vmware
    • hyperv
  • ディレクトリベースのプロジェクト管理
    • vmを操作するときは専用のディレクトリを作成する

インストール

ubuntu, debian

$ curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
$ sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
$ sudo apt-get update && sudo apt-get install vagrant

$ sudo dpkg-reconfigure virtualbox-dkms # 再設定
$ sudo dpkg-reconfigure virtualbox
$ sudo apt-get install linux-headers-generic
$ sudo modprobe vboxdrv # kernel moduleのリロード

具体例

ubuntuの仮想マシンを作成する

$ mkidr <foo> && cd <foo>
$ vagrant init ubuntu/kinetic64 
$ vagrant box add ubuntu/kinetic64 

作成した仮想マシンを起動

$ vagrant up

作成した仮想マシンにsshする

$ vagrant ssh

vagrantのコマンド各種

  • vagrant box list
    • 取得したbox(仮想マシンのテンプレート)の取得
  • vagrant halt
    • 仮想マシンの電源OFF
  • vagrant up
    • 仮想マシンの電源ON
  • vagrant suspend
    • 仮想マシンのサスペンド
  • vagrant destroy
    • 仮想マシンの破棄

参考