Vagrant
初期処理
$ vagrant init
仮想マシン起動まで
box 追加
# vagrant box add centos6.5 url
centos6.5
- box名
url
- ダウンロードするURL
例
$ vagrant box add centos7.1 http://cloud.centos.org/centos/7/vagrant/x86_64/images/CentOS-7-Vagrant-1505-x86_64-01.box
box 表示
# vagrant box list bento/centos-6.7 (virtualbox, 2.2.3) bento/fedora-23 (virtualbox, 2.2.3) centos6.5 (virtualbox, 0) centos6.6 (virtualbox, 0) centos7 (virtualbox, 0)
仮想マシン複製
注意
- 複製元マシンはシャットダウンされる
Vagrantfileがおいてある場所へ移動
複製作成
# vagrant package
box 取り込み
# vagrant box add boxname package.box
起動と接続
# vagrant up # vagrant ssh
show log
info
VAGRANT_LOG=info vagrant up
debug
VAGRANT_LOG=debug vagrant up
プロビジョニングのみの実施
- 起動済のインスタンスに対して実施
- 設定は Vagrantfile のプロビジョニングの実施 を参照
$ vagrant provision
other
全仮想マシンの状況確認
$ vagrant global-status
無効なエントリーを除外
$ vagrant global-status --prune
SSH 接続したい
$ vagrant ssh-config --host hostname >> ~/.ssh/config
仮想マシン削除
$ vagrant destroy
box 削除
$ vagrant box list $ vagrant box remove boxname
ホスト <=> ゲスト間のファイル共有
やること
- ホストとゲスト間でのファイルの共有
- ただ共有しただけだとホストを更新した場合に、ゲスト側に更新通知(inotify) がされないので、更新通知されるようにする
ホスト側にてプラグインのインストール
共有用
$ vagrant plugin install vagrant-vbguest
更新通知用
$ vagrant plugin install vagrant-fsnotify
ゲストの再起動
$ vagrant reload
Vagrantfile の修正
config.vm.synced_folder "/Users/r0306/Documents/project/gitbook/doc/", "/srv/engineering/", fsnotify: true
ホスト側更新を検知し、ゲスト側に通知
$ vagrant fsnotify
エラー
Mac 移設時エラーが発生。下記エラーは .vagrant/machines/default/virtualbox/creator_uid を変更してあげる
The VirtualBox VM was created with a user that doesn't match the current user running Vagrant. VirtualBox requires that the same user be used to manage the VM that was created. Please re-run Vagrant with that user. This is not a Vagrant issue. The UID used to create the VM was: 502 Your UID is: 501