LoginSignup
0
0

More than 1 year has passed since last update.

vagrant

Posted at

前提としてvirtualboxがインストールされているものとする。
vagrantのインストールはここから。https://www.vagrantup.com/downloads

vagrantにbox(仮想マシンのテンプレート)を追加

https://app.vagrantup.com/boxes/search
から検索

vagrant box add ubuntu/hirsute64

vagrantfileの作成

-m(--minimal)なしだとコメントが表示される。

vagrant init -m

以降のコマンドはvagrant global-statusを除いてvagrantfileがあるディレクトリからコマンドをうつ。

Vagrantfileを見てみると以下のようになっているのでconfig.vm.boxを先程addしたubuntu/hirsute64に指定する。

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "base"
end

config.vm.boxを変更

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/hirsute64"
end

VMの起動

vagrant up

Oracle VM VirtualBox Managerを確認するとrunningになっているのが確認できる。

VMのステータス確認

vagrant status

すべてのVMのステータス表示

このコマンドはvagrantfileがあるdirectoryからでなくてもよい。  

vagrant global-status

VMのshut-down

vagrant halt

VMのshut-down,削除(VM内での変更は保存されない)

vagrant destroy

実践

boxのみinitコマンドから指定することができる。

vagrant init -m ubuntu/hirsute64

Vagrantfileができるので見てみる。

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/hirsute64"
end

ネットワークの設定を追加する。
注意点としてvirtualboxのfile=>host-network-managerで指定されているネットワークの範囲内にipを指定しなければエラーになった。
私の環境ではvboxnet0 192.168.56.1/24に設定されていたのでipを"192.168.56.10"に設定。

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/hirsute64"
  config.vm.network "private_network", ip: "192.168.56.10"
end

ssh接続

vagrant ssh

VM内ではユーザーはvagrant,パスワードもvagrantにデフォルトでなっている。
sudo suでルートユーザーになれる。

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