vagrantコマンド一覧
|
はじめに
vagrantを使っていると、あまり使用しないコマンドを忘れてちょくちょく調べる為、纏めておく。
vagrantコマンド一覧
# | 構文 | 意味 |
---|---|---|
1 | vagrant package --base [VM名] --output [出力box名] | VMからBOX作成 |
2 | vagrant box add --name [Box名] [Boxファイル名] | Boxの登録 |
3 | vagrant box remove [Box名] | Boxの削除 |
4 | vagrant box list | Box一覧 |
5 | vagrant init [Box名] | vagrant初期化 |
6 | vagrant up | vm起動 |
7 | vagrant halt | vm停止 |
8 | vagrant reload | vm再起動 |
9 | vagrant destroy [-f] | vm削除 -f:強制 |
10 | vagrant status | vm状態 |
11 | vagrant -v | バージョン確認 |
12 | vagrant version | バージョン確認 latestの確認 |
コマンドサンプル
vagrantのコマンドを以下の通り確認をする。
1.Box作成
1 2 3 4 |
G:\003_Vargrant>vagrant package --base UbuntuServer16.04.3LTS_VB5.1.28 ==> UbuntuServer16.04.3LTS_VB5.1.28: Exporting VM... ==> UbuntuServer16.04.3LTS_VB5.1.28: Compressing package to: G:/003_Vargrant/package.box |
2.Box登録
1 2 3 4 5 6 7 8 |
G:\003_Vargrant\box>vagrant box add --name ubntu160403LTS_5128 ubntu160403LTS_5128.box ==> box: Box file was not detected as metadata. Adding it directly... ==> box: Adding box 'ubntu160403LTS_5128' (v0) for provider: box: Unpacking necessary files from: file://G:/003_Vargrant/box/ubntu160403LTS_5128.box box: Progress: 100% (Rate: 704M/s, Estimated time remaining: 0:00:01) ==> box: Successfully added box 'ubntu160403LTS_5128' (v0) for 'virtualbox'! |
3.Box削除
1 2 3 |
G:\003_Vargrant\box>vagrant box remove ubntu160403LTS_5128 Removing box 'ubntu160403LTS_5128' (v0) with provider 'virtualbox'... |
4.BOX一覧
1 2 3 |
G:\003_Vargrant\box>vagrant box list ubntu160403LTS_5128 (virtualbox, 0) |
5.vagrant初期化
1 2 3 4 5 6 |
G:\003_Vargrant\PythonPrj>vagrant init ubntu160403LTS_5128 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. |
6.vm起動
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
G:\003_Vargrant\PythonPrj>vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'ubntu160403LTS_5128'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: PythonPrj_default_1505785454270_5671 ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 (guest) => 2222 (host) (adapter 1) ==> 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: default: Vagrant insecure key detected. Vagrant will automatically replace default: this with a newly generated keypair for better security. default: default: Inserting generated public key within guest... default: Removing insecure key from the guest if it's present... default: Key inserted! Disconnecting and reconnecting using new SSH key... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Mounting shared folders... default: /vagrant => G:/003_Vargrant/PythonPrj |
7.vm停止
1 2 3 |
G:\003_Vargrant\PythonPrj>vagrant halt ==> default: Attempting graceful shutdown of VM... |
8.vm再起動
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
G:\003_Vargrant\PythonPrj>vagrant reload ==> default: Clearing any previously set forwarded ports... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 (guest) => 2222 (host) (adapter 1) ==> 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! ==> default: Checking for guest additions in VM... ==> default: Mounting shared folders... default: /vagrant => G:/003_Vargrant/PythonPrj ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision` ==> default: flag to force provisioning. Provisioners marked to run always will still run. |
9.vm削除
1 2 3 4 5 |
G:\003_Vargrant\PythonPrj>vagrant destroy default: Are you sure you want to destroy the 'default' VM? [y/N] y ==> default: Forcing shutdown of VM... ==> default: Destroying VM and associated drives... |
10.vm状態
1 2 3 4 5 6 7 8 9 10 |
G:\003_Vargrant\PythonPrj>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`. |
11.version確認
1 2 3 |
G:\003_Vargrant\PythonPrj>vagrant -v Vagrant 2.0.0 |
12.version確認
1 2 3 4 5 6 |
G:\003_Vargrant\PythonPrj>vagrant version Installed Version: 2.0.0 Latest Version: 2.0.0 You're running an up-to-date version of Vagrant! |
UbuntuServer16.04.3LTS_VB5.1.28