- vagrant box add
- boxの追加。
 boxを追加しておくと、すでにあるLinuxイメージをローカルにダウンロードし、登録しておくイメージ。
 追加されたboxは初期化することですぐに利用出来る様になる。
 boxのダウンロードはある程度時間が掛かる。
 boxファイルは色々な所に落ちているが、下記の様にまとめサイト的なものもある。
 
 http://www.vagrantbox.es/
 
 $ vagrant box add [box-name] [box-url] 例) $ vagrant box add centos6.4 https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box
 
- vagrant box list
- すでに追加されているboxの一覧を確認する。
 今までbox addコマンドで追加したboxの一覧が確認出来る。
 
 $ vagrant box list 例) $ vagrant box list centos6.4 (virtualbox, 0) centos6.4-30gb (virtualbox, 0) centos6.4-nomal (virtualbox, 0) centos6.5 (virtualbox, 0) centos7.0 (virtualbox, 0) test (virtualbox, 0)
 
- vagrant box remove
- すでに追加してあるboxファイルを削除する。
 
 $ vagrant box remove [box name] 例) $ vagrant box remove test Removing box 'test' (v0) with provider 'virtualbox'... $ vagrant box list centos6.4 (virtualbox, 0) centos6.4-30gb (virtualbox, 0) centos6.4-nomal (virtualbox, 0) centos6.5 (virtualbox, 0) centos7.0 (virtualbox, 0)
 
- vagrant init
- boxを初期化する。
 これをする事でVagrantfileが作成され、VMの細かい設定が出来るようになる。
 
 $ vagrant init [box-name] 例) $ vagrant init centos6.4 A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant.
- vagrant up
- VMを起動する。Vagrantfileに書かれた内容に基づいたVMが作成され、起動する。
 
 $ vagrant up 例) $ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'centos6.4'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: test-vm ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: hostonly ==> default: Forwarding ports... default: 22 => 2222 (adapter 1) ==> default: Running 'pre-boot' VM customizations... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Connection timeout. Retrying... default: Warning: Connection timeout. Retrying... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Configuring and enabling network interfaces... ==> default: Mounting shared folders... default: /vagrant => C:/cygwin64/home/username/VirtualBoxMachines/test-vm
- vagrant halt
- VMを停止する。
 
 $ vagrant halt ==> default: Attempting graceful shutdown of VM... 
- vagrant suspend
- VMを一時停止する
 
 $ vagrant suspend ==> default: Saving VM state and suspending execution... 
- vagrant resume
- 一時停止されているVMを再開させる
 
 $ vagrant resume ==> default: Resuming suspended VM... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key ==> default: Machine booted and ready!
- vagrant status
- VMのステータスを確認出来る
 
 $ vagrant status Current machine states: default running (virtualbox) The VM is running. To stop this VM, you can run `vagrant halt` to shut it down forcefully, or you can run `vagrant suspend` to simply suspend the virtual machine. In either case, to restart it again, simply run `vagrant up`. 
- vagrant ssh
- vagrant経由で起動させたVMにsshでログインする
 
 $ vagrant ssh Last login: Tue Feb 3 10:49:53 2015 from 192.168.33.100 [vagrant@vagrant ~]$ 
- vagrant global-status
- vagrant全体の状況が確認出来る。1度起動したVMはIDが振られる。
 このIDを指定することで、対象のVMディレクトリ配下に移動しなくても起動出来る。
 
 $ vagrant global-status id name provider state directory -------------------------------------------------------------------------------------------------- 6dd4f19 default virtualbox saved C:/cygwin64/home/user-name/vbox-cent64 b735130 default virtualbox poweroff C:/cygwin64/home/user-name/VirtualBoxMachines/vbox-cent64-1 The above shows information about all known Vagrant environments on this machine. This data is cached and may not be completely up-to-date. To interact with any of the machines, you can go to that directory and run Vagrant, or you can use the ID directly with Vagrant commands from any directory. For example: "vagrant destroy 1a2b3c4d" 
- vagrant global-status --prune
- global-statusで確認した時、本来削除したはずのVMの管理情報が残っている場合がある。
 そういった不要情報を綺麗にした状態にするためのオプションが「prune」
 
 ■通常のコマンドでステータス確認$ vagrant global-status id name provider state directory ------------------------------------------------------------------------------------------------------ 17033d9 default virtualbox poweroff C:/cygwin64/home/user-name/virtualBox ← 削除済みなのに表示されている 754da86 default virtualbox poweroff C:/cygwin64/home/user-name/virtualBox_CentOS6.5 ← 削除済みなのに表示されている 6dd4f19 default virtualbox poweroff C:/cygwin64/home/user-name/vbox-cent64 e8c4ab5 default virtualbox poweroff C:/cygwin64/home/user-name/VirtualBoxMachines/vbox-cent64-1-tmp ← 削除済みなのに表示されている 2de0695 default virtualbox running C:/cygwin64/home/user-name/VirtualBoxMachines/vbox-cent64-1 The above shows information about all known Vagrant environments on this machine. This data is cached and may not be completely up-to-date. To interact with any of the machines, you can go to that directory and run Vagrant, or you can use the ID directly with Vagrant commands from any directory. For example: "vagrant destroy 1a2b3c4d" 
 ■削除済み情報を綺麗にして表示させる。$ vagrant global-status --prune C:/cygwin64/home/user-name/vbox-cent64/Vagrantfile:5: warning: already initialized constant VAGRANTFILE_API_VERSION C:/cygwin64/home/user-name/virtualBox_CentOS6.5/Vagrantfile:5: warning: previous definition of VAGRANTFILE_API_VERSION was here C:/cygwin64/home/user-name/VirtualBoxMachines/vbox-cent64-1/Vagrantfile:5: warning: already initialized constant VAGRANTFILE_API_VERSION C:/cygwin64/home/user-name/vbox-cent64/Vagrantfile:5: warning: previous definition of VAGRANTFILE_API_VERSION was here id name provider state directory -------------------------------------------------------------------------------------------------- 6dd4f19 default virtualbox poweroff C:/cygwin64/home/user-name/vbox-cent64 2de0695 default virtualbox running C:/cygwin64/home/user-name/VirtualBoxMachines/vbox-cent64-1 The above shows information about all known Vagrant environments on this machine. This data is cached and may not be completely up-to-date. To interact with any of the machines, you can go to that directory and run Vagrant, or you can use the ID directly with Vagrant commands from any directory. For example: "vagrant destroy 1a2b3c4d" C:/cygwin64/home/user-name/VirtualBoxMachines/vbox-cent64-1/Vagrantfile:5: warning: already initialized constant VAGRANTFILE_API_VERSION C:/cygwin64/home/user-name/VirtualBoxMachines/vbox-cent64-1/Vagrantfile:5: warning: previous definition of VAGRANTFILE_API_VERSION was here 
- vagrant destroy
- 作成されているVMを削除する。このコマンドを実行することで、VirtualBox上からもマシンが消える。
 また、global-statusに出てくるIDを末尾につけることで、該当のVMのディレクトリに移動しなくても削除する事が可能。
 
 $ vagrant destroy 
- vagrant box repackage
- 既に追加済みのBoxをカレントディレクトリにpackage.boxファイルとして出力する。
 
 $ vagrant box repackage [provider_name] [version] 
 providerやversionはvagrant box listコマンドを打つと出てくる
 $ vagrant box list centos6.4 (virtualbox, 0) 
 この場合、コマンドは下記の様になる。
 $ vagrant box repackage virtualbox 0 
 
http://lab.raqda.com/vagrant/cli/
