概要
BOXの作成
詳細
BOXの作成
BOXを作成する手順
$ mkdir create_box $ cd create_box $ vagrant init # => 編集内容の詳細は後述 $ vi Vagrantfile # VM起動。※denreiは自作のgemで実行完了時にダイアログを表示するだけです。 $ vagrant up;denrei Bringing machine 'default' up with 'virtualbox' provider... [default] Importing base box 'ubuntu-12.04-x64'... : : # 中略 : _ _ _ _ __ _ __ _____ _(_)___(_) ___ _ __ ___ _ _ ___ ___ ___ ___ ___| | | '_ \| '__/ _ \ \ / / / __| |/ _ \| '_ \ / __| | | |/ __/ __/ _ \/ __/ __| | | |_) | | | (_) \ V /| \__ \ | (_) | | | | \__ \ |_| | (_| (_| __/\__ \__ \_| | .__/|_| \___/ \_/ |_|___/_|\___/|_| |_| |___/\__,_|\___\___\___||___/___(_) |_| # SSH接続 $ vagrant ssh $ git version git version 1.7.9.5 $ figlet 'box' _ | |__ _____ __ | '_ \ / _ \ \/ / | |_) | (_) > < |_.__/ \___/_/\_\ $ exit $ vagrant package --base sample_box_template [sample_box_template] Attempting graceful shutdown of VM... : # 略(package.boxができます) $ vagrant destroy # 自作BOXをBOXに追加 $ vagrant box add sample_box package.box Downloading or copying the box... Extracting box...ate: 750M/s, Estimated time remaining: --:--:--) Successfully added box 'sample_box' with provider 'virtualbox'! # boxの追加を確認 $ vagrant box list sample_box (virtualbox) ubuntu-12.04-x64 (virtualbox)
BOXを利用する手順
$ mkdir create_box_user $ cd create_box_user $ vagrant init # => 編集内容の詳細は後述 $ vi Vagrantfile # VM起動。※denreiは自作のgemで実行完了時にダイアログを表示するだけです。 $ vagrant up;denrei Bringing machine 'default' up with 'virtualbox' provider... [default] Importing base box 'sample_box'... : : # 中略 : [default] Mounting shared folders... [default] -- /vagrant # SSH接続 $ vagrant status $ vagrant ssh # BOXに含めておいたgitがインストール済みであることを確認 $ git version git version 1.7.9.5 # BOXに含めておいたfigletがインストール済みであることを確認 $ figlet 'box' _ | |__ _____ __ | '_ \ / _ \ \/ / | |_) | (_) > < |_.__/ \___/_/\_\ $ exit $ vagrant destroy
Vagrantfile(BOXの元)
Vagrantfile
# -*- mode: ruby -*- # vi: set ft=ruby : VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.provider :virtualbox do |vb| vb.name = "sample_box_template" end config.vm.box = "ubuntu-12.04-x64" config.vm.provision "shell", inline: <<-EOS sudo apt-get install git -y sudo apt-get install figlet -y figlet 'one provision success!' EOS end
Vagrantfile(自作BOXを利用)
Vagrantfile
# -*- mode: ruby -*- # vi: set ft=ruby : VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.provider :virtualbox do |vb| vb.name = "sample_box_user" end config.vm.box = "sample_box" end