【Vagrant】 独自のboxを作成する
環境 Vagrant 1.8.1 VirtualBox 5.0.12
既存のVMからboxイメージを作成する
ホスト側から以下のようにする。
PS> vagrant package --base VMName --output Custom.box ==> VMName: Attempting graceful shutdown of VM... VMName: Guest communication could not be established! This is usually because VMName: SSH is not running, the authenticationinformation was changed, VMName: or some other networking issue. Vagrant will force halt, if VMName: capable. ==> VMName: Forcing shutdown of VM... ==> VMName: Clearing any previously set forwarded p orts... ==> VMName: Exporting VM... ==> VMName: Compressing package to: Custom.box
--base
はVirtualBox上の名前
--output
は新しいboxの名前
【参考】
Vagrant:package作成時「VM not created. Moving on…」をエラーが出たら | ログってなんぼ
--output
が未指定だと、package.box
になる
新しいboxファイルを、vagrantのboxに登録する
PS> vagrant box add NewBox Custom.box ==> box: Box file was not detected as metadata. Adding it directly... ==> box: Adding box 'NewBox' (v0) for provider: box: Unpacking necessary files from: file://Custom.box box: Progress: 100% (Rate: 461M/s, Estimated time remaining: --:--:--) ==> box: Successfully added box 'NewBox' (v0) for 'virtualbox'! PS> vagrant box list NewBox (virtualbox, 0) bento/centos-7.1 (virtualbox, 2.2.2)
となる。