LoginSignup
0
0

More than 1 year has passed since last update.

Vagrant入門②:Vagrantで仮想マシンの起動

Posted at

環境
・macOS

Vagrantのインストール

Vagrantダウンロードサイト

今回はhomebrewを使用してインストール

$ brew install vagrant
$ vagrant -v

VirtualBoxのインストール

VirtualBoxダウンロードサイト

homebrewでもインストールできますが、少し不安だったのでシンプルにインストールしました。

$ VBoxManage -v

Boxの追加

Discover Vagrant Boxes

vagrantコマンドを使用してBoxのダウンロード
仮想デスクトップ環境は3) virtualboxを選択

$ vagrant box add centOS/7
==> box: Loading metadata for box 'centOS/7'
    box: URL: https://vagrantcloud.com/centOS/7
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.

1) hyperv
2) libvirt
3) virtualbox
4) vmware_desktop

Enter your choice: 3
==> box: Adding box 'centos/7' (v2004.01) for provider: virtualbox
    box: Downloading: https://vagrantcloud.com/centos/boxes/7/versions/2004.01/providers/virtualbox.box
Download redirected to host: cloud.centos.org
    box: Calculating and comparing box checksum...
==> box: Successfully added box 'centos/7' (v2004.01) for 'virtualbox'!


$ vagrant box list
centos/7 (virtualbox, 2004.01)

Vagrantfileの初期化

Vagrantfileを作成するディレクトリの作成 ※ファイル名はなんでも良い。今回はcentos7で作成。

$ mkdir centos
$ cd centos

ディレクトリ内にVagrantfileの作成。
Vagrantfileの初期化コマンドはvagrant init {box_name}
先ほどインストールしたBoxを指定する。

$ vagrant init centOS/7
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.


$ ls -l
-rw-r--r--  1 user  staff  3014 10 14 19:39 Vagrantfile

仮想マシンの起動・停止

仮想マシンの起動、SSHの接続

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centOS/7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'centOS/7' version '2004.01' is up to date...
...(略)


$ vagrant status
default                   running (virtualbox)


$ vagrant ssh
[vagrant@localhost ~]$

仮想マシンの停止

$ vagrant halt
==> default: Attempting graceful shutdown of VM...


$ vagrant status
default                   poweroff (virtualbox)

参照

WEB ARCH LABO / Vagrant入門 / macOS ではじめる Vagrant

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