devops之vagrant
vagrant 简介
vagrant - 管理VM, 可用于隔离性更好环境的搭建 (VM vs Docker)
概念
Vagrant Box
(https://app.vagrantup.com/boxes/search)
Boxes are globally stored for the current user. Each project uses a box as an initial image to clone from, and never modifies the actual base image.
Install Box
ubuntu 18.04
vagrant box add hashicorp/bionic64 |
Mac Storage:
~/.vagrant.d/boxes
示例
创建Vagrantfile
Vagrantfile 指定box,以及配置, 一个最简单的vagrant file
Vagrant.configure("2") do |config|
# box settings
config.vm.box = "hashicorp/bionic64"
config.vm.box_version = "1.0.282"
# Provider Settings
config.vm.provider "virtualbox" do |vb|
end
end注意:
By default, Vagrant shares your project directory (the one containing the Vagrantfile) to the /vagrant
directory in your guest machine.
You can configure Vagrant to run this shell script when setting up the machine,
config.vm.provision :shell, path: "bootstrap.sh" |
常用命令
switch to the folder contains Vagrantfile and run
vagrant up
for vm provisionrun
vagrant ssh
to ssh to vm, rungit --version
to verify whether the git is automatically installed on the vmYou can use
vagrant status
to check vm status,vagrant halt
to poweroff vm andvagrant destory
to delete the vm