はじめてのVagrant

Vagrantをちょっとみました。インストール手順まとめました。

Vagrant?ってなった人は、これをお勧めします。
Vagrant導入手順から本ブログに記載します!
qiita.com

1.Vagrantをインストール

これを参考にしました。
qiita.com

brew cask install virtualbox
brew cask install vagrant
brew cask install vagrant-manager

2.VMディレクトリの作成

mkdir -p ~/vm/vm-dir/
cd ~/vm/vm-dir/

3.Vagrantfileの生成

私は、CentOS7を使います。

vagrant init --minimal  centos/7

4.VMの起動とSSHログイン

VMを起動します。

vagrant up
==> default: Checking if box 'centos/7' is up to date...
==> 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: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default:
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Rsyncing folder: /Users/hoge/vm/vm-dir/ => /vagrant
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

起動状況の確認

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`.

SSHログイン

vagrant ssh
[vagrant@localhost ~]$

SSHログインできました。
ちなみに、「VMのシャットダウンは vagrant halt, 休止は vagrant suspend です。」

疑問1)boxって何?
公式ドキュメントより。boxとは、Vagrant環境のためのパッケージフォーマットと書いてあるけど。よくわからん。
www.vagrantup.com