0%

Vagrant Notes

Vagrant Notes

Download VirtualBox (please first)
Download Vagrant

Commands

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Vagrant 1.9.7
vagrant -v
# Help
vagrant
# Create Vagrantfile
vagrant init
# Boxes
vagrant box list
vagrant box add laravel/homestead
vagrant box remove laravel/homestead
# Status
vagrant global-status
# SSH
vagrant ssh # ssh vagrant@127.0.0.1 -p 2222
# After editting config file...
# provisions the vagrant machine
vagrant provision
# restarts vagrant machine, loads new Vagrantfile configuration
vagrant reload
# Shut down machine
vagrant halt
# Remove machine
vagrant destroy
vagrant destroy 1a2b3c4d
# List all providers
vagrant provider
1
2
3
4
5
6
7
8
9
10
# Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64" # change me
# forwarded port
config.vm.network "forwarded_port", guest: 80, host: 8080 # uncomment me
# host-only
config.vm.network "private_network", ip: "192.168.33.10" # uncomment me
end

Find Boxes

https://vagrantcloud.com/search
https://app.vagrantup.com/ubuntu
https://app.vagrantup.com/centos

Vagrant Parallels Provider

github.com/Parallels/vagrant-parallels
Vagrant Cloud - parallels sort by downloads
Vagrant Cloud - parallels official

1
2
3
4
5
vagrant plugin install vagrant-parallels
vagrant plugin list
vagrant init parallels/ubuntu-16.04
vagrant up --provider=parallels

Laravel Homestead

1
2
3
4
5
6
7
8
9
10
11
12
13
14
git clone https://github.com/laravel/homestead.git Homestead
cd Homestead
sh init.sh
vim Homestead.yaml
provider: parallels
folders:
- map: ~/Your_Code_folders
# Optional
sudo vim /etc/hosts
192.168.10.10 homestead.app
vagrant up

Packaging

https://www.vagrantup.com/docs/vagrant-cloud/boxes/create.html#creating-boxes-via-the-vagrant-enterprise-web-interface

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
vagrant package
Usage: vagrant package [options] [name|id]
Options:
--base NAME Name of a VM in VirtualBox to package as a base box (VirtualBox Only)
--output NAME Name of the file to output
--include FILE,FILE.. Comma separated additional files to package with the box
--vagrantfile FILE Vagrantfile to package with the box
-h, --help Print this help
# NOTE
vagrant package --vagrantfile Vagrantfile.package
upload to https://app.vagrantup.com/

「vagrant package」可以為任何”Virtualbox的”虛擬機創建box,而不一定非得是vagrant啟動的虛擬機,只要「–base」參數指向Virtualbox的某個虛擬機名字即可。
原文網址:https://kknews.cc/zh-tw/other/bamzo6.html

Important Issue Solved @skinneejoe

  1. sudo passwd ubuntu password to vagrant
  2. shutdown vm
  3. rm .vagrant/machines/default/virtualbox/private_key
  4. Package the box
  5. in new boxex Vagrantfile include: config.ssh.username = 'ubuntu', config.ssh.password = 'vagrant'

Uninstall Vagrant

1
2
Using uninstall.tool
rm -rf ~/.vagrant.d/

Build your own environment

  1. Editting existing box from vagrant cloud
  2. install some stuff and upload to vagrant cloud