1. 安装
# 安装vagrant
sudo apt install -y virtualbox vagrant
# 设置代理
export http_proxy="socks5://127.0.0.1:1080"
export https_proxy=$http_proxy
2. 命令
2.1. basic
-
vagrant version
-
vagrant login
需将SOCKS5代理切换成HTTP代理登录
-
vagrant global-status
-
vagrant init -f -m [--box-version VERSION] BOX_NAME [URL]
-
vagrant up [NAME|ID]
-
vagrant ssh
-
vagrant suspend
-
vagrant resume
-
vagrant halt
-
vagrant reload
-
vagrant status
-
vagrant package
-
vagrant provision
刷新配置
-
vagrant destroy -f
2.2. box
-
vagrant box add [boxName|file|url] [--box-version VALUE] [--clean] [--force] [--insecure] [file: --name VALUE]
-
vagrant box list
-
vagrant box outdated [--global]
-
vagrant box prune -f [--name VALUE] [--dry-run]
-
vagrant box remove NAME [--box-version VALUE] [-a] [-f]
-
vagrant box repackage
-
vagrant box update [--box VALUE] (in vagrant dir)
3. 网络
3.1. 端口转发
Vagrantfile
# host 端口必须大于1024
config.vm.network "forwarded_port", guest: 80, host: 8080 [,protocol: "[tcp|udp]"]
3.2. 私有网络
Vagrantfile
# static ip
config.vm.network "private_network", ip: "192.168.0.11"
# dhcp
config.vm.network "private_network", type: 'dhcp'
3.3. 公有网络
Vagrantfile
# static ip
config.vm.network "public_network", ip: "192.168.0.11"[, brige: "wlp2s0"]
# dhcp
config.vm.network "public_network"
4. Vagrantfile配置
Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.hostname = "HOSTNAME"
config.vm.provider "virtualbox" do |vb|
vb.name = "VIRTUAL_BOX_HOSTNAME"
vb.memory = "2048"
vb.cpus = 2
vb.gui = false
end
config.vm.network "public_network", ip: "192.168.0.111"
end