vagrantで仮想環境を複製する
環境を複製しておいてバックアップとか思い出にとっておきたいと思った。
環境
vagrant (1.0.7)
(1)今まで使っていた仮想環境をエクスポート(パッケージ化)する
boxファイルを読み込んでupしてsshしていた仮想環境。これをboxとしてエクスポートをする。
$ vagrant package [default] Clearing any previously set forwarded ports... [default] Creating temporary directory for export... [default] Exporting VM... [default] Compressing package to: /Users/koji/second_mathine/package.box
パケージ化には時間がかかる。
すると、同じディレクトリにpakage.boxができる。
今度は、こいつをインポートする。
(2)boxのインポート
二つ目の仮想環境は、別ディレクトリで作ることにする。
$ cd second_machine $ cp ../package.box . $ va box add debian2 package.box [vagrant] Downloading with Vagrant::Downloaders::File... [vagrant] Copying box to temporary location... [vagrant] Extracting box... [vagrant] Verifying box... [vagrant] Cleaning up downloaded box... [retina_koji@retina-no-MacBook-Pro:~/de
(3)Vagrantfileの初期化
$ vagrant init debian2 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.
(4)VM起動
$ vagrant up [default] Importing base box 'debian2'... [default] Matching MAC address for NAT networking... [default] Clearing any previously set forwarded ports... [default] Forwarding ports... [default] -- 22 => 2222 (adapter 1) [default] Creating shared folders metadata... [default] Clearing any previously set network interfaces... [default] Booting VM... [default] Waiting for VM to boot. This can take a few minutes. [default] VM booted and ready for use! [default] The guest additions on this VM do not match the install version of VirtualBox! This may cause things such as forwarded ports, shared folders, and more to not work properly. If any of those things fail on this machine, please update the guest additions and repackage the box. Guest Additions Version: 4.1.8 VirtualBox Version: 4.2.8 [default] Mounting shared folders... [default] -- v-root: /vagrant
(5)SSHで確認
$ vagrant ssh Linux debian 2.6.32-5-amd64 #1 SMP Mon Feb 25 00:26:11 UTC 2013 x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. You have new mail. Last login: Thu Mar 14 01:47:47 2013 from 10.0.2.2 [vagrant@debian:~] (no branch) $
これでデザイナーさんに簡単に環境を渡せます。
マシンを同時に複数起動する場合はポートとIPアドレスが被らないように設定する必要ありとのこと。