vagrant คืออะไร ? และวิธีการใช้อย่างง่าย
$ brew cask install vagrant
*** ในตอนนี้ vagrant 2.2.6 รองรับ virtualbox ไม่เกิน version 6.0
$ mkdir vagrant-example && cd vagrant-example
# เป็นการ initail เพื่อให้ได้ vagrantfile
$ vagrant init
# or
$ vagrant init centos-7
# เพื่อเป็นการ init ตัว os ที่เราต้องการจะสร้าง
ภายใน VagrantFile
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
end
Vagrant.configure("2") do |config|
config.vm.box = "centos-7"
config.vm.network "forwarded_port", guest: 80, host: 8080, id: "nginx" # เป็นการ forward port ภายในออกนอก
config.vm.provision "shell", inline: <<-SHELL
sudo yum install epel-release -y
sudo yum update -y
sudo yum install nginx -y
sudo systemctl start nginx
SHELL
end
$ vagrant up
ทั้งนี้ยังสามารถสร้างใน provider เช่น DigitalOcean , Aws , ….
$ vagrant box # manages boxes: installation, removal, etc.
$ vagrant destroy # stops and deletes all traces of the vagrant machine
$ vagrant global-status # outputs status Vagrant environments for this user
$ vagrant halt # stops the vagrant machine or Shutdown
$ vagrant help # shows the help for a subcommand
$ vagrant init # initializes a new Vagrant environment by creating a Vagrantfile
$ vagrant login #log in to HashiCorp’s Atlas
$ vagrant package #packages a running vagrant environment into a box
$ vagrant plugin # manages plugins: install, uninstall, update, etc.
$ vagrant port # displays information about guest port mappings
$ vagrant powershell # connects to machine via powershell remoting
$ vagrant provision # provisions the vagrant machine
$ vagrant push #deploys code in this environment to a configured destination
$ vagrant rdp # connects to machine via RDP
$ vagrant reload # restarts vagrant machine, loads new Vagrantfile configuration
$ vagrant resume # resume a suspended vagrant machine
$ vagrant snapshot # manages snapshots: saving, restoring, etc.
$ vagrant ssh # connects to machine via SSH
$ vagrant ssh-config # outputs OpenSSH valid configuration to connect to the machine
$ vagrant status # outputs status of the vagrant machine
$ vagrant suspend # suspends the machine
$ vagrant up # starts and provisions the vagrant environment
$ vagrant version # prints current and latest Vagrant version