0
0

vagrant destroy と vagrant box コマンドの違いを整理した

Posted at

vagrantとは

詳しくは下記の記事を読んでください。
https://t-cr.jp/article/5a179bc8febae3aa

【vagrant】コマンド一覧
https://qiita.com/oreo3/items/4054a4120ccc249676d9

【vagrant destroyとvagrant box removeコマンドの違い】

vagrant destroy:
Vagrantで作成した特定の仮想マシンを削除するためのコマンドです。
この操作は、仮想マシンが占有するリソース(ディスク、メモリ、ネットワーク設定)を解放しますが、ボックスは削除しません。

vagrant box:
ボックスは仮想マシンを作成するためのテンプレートであり、仮想マシンを作成する際に使用されますが、ボックス自体は仮想マシンとは別に管理されます。
ボックスを削除しても、すでにそのボックスから作成された仮想マシンには影響しませんが、新しい仮想マシンを作成する際にそのボックスを使うことはできなくなります。

【仮想マシンを削除するまでの手順】

  • 全仮想マシンの一覧を表示する
$ vagrant global-status

id       name              provider   state    directory                        
------------------------------------------------------------------------------------
12abcde  vagrant1  virtualbox running  C:/Users/xxx/xxx/vagrant
34fg5hi  vagrant2  virtualbox poweroff  C:/Users/xx/xxx/vagrant
  • 仮想マシンの停止
    仮想マシンが「running」の場合、vagrant destroyコマンドは仮想マシンを停止した後に削除します。
$ vagrant halt <id>
  • 仮想マシンを削除する
$ vagrant destroy <id>
  • 確認プロンプト
    vagrant destroyコマンドを実行すると、仮想マシンを削除するかどうかの確認プロンプトが表示されます。
    「y」を入力して確定します。
vagrant<番号>: Are you sure you want to destroy the 'vagrant<番号>' VM? [y/N] y
  • 強制削除
    確認プロンプトをスキップして強制的に削除したい場合は、-fオプションを使用します。
$ vagrant destroy <machine_id> -f

【仮想マシンを作成するためのテンプレートを削除するまでの手順】

  • boxの一覧を表示
$ vagrant box list

ubuntu/test1    (virtualbox, 1708.01)
ubuntu/test2    (virtualbox, 1353.1.0)
  • 指定されたボックスを削除するコマンド
$ vagrant box remove ubuntu/test1
  • 仮想化プロバイダを指定して削除する場合
$ vagrant box remove ubuntu/test1 --provider virtualbox
  • 特定のバージョンを削除する場合
    *リストされたボックスにはバージョン番号が0としか表示されていないため、通常はバージョンを指定する必要はありません。
$ vagrant box remove ubuntu/test1 --box-version 0
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0