创建一个ubuntu18.04虚拟机的过程:
1 2 3 4
| vagrant init ubuntu/bionic64 vagrant up
vagrant ssh
|
/vagrant
目录默认共享宿主机器上启动vagrant命令的当前目录
可以通过config.vm.provision
为vm预装软件
比如预装个apache2
1 2 3 4 5 6 7 8
| #!/usr/bin/env bash
apt-get update apt-get install -y apache2 if ! [ -L /var/www ]; then rm -rf /var/www ln -fs /vagrant /var/www fi
|
1 2 3 4
| Vagrant.configure("2") do |config| config.vm.box = "ubuntu/bionic64" config.vm.provision :shell, path: "bootstrap.sh" end
|
暴露端口(端口转发)
1 2 3 4 5
| Vagrant.configure("2") do |config| config.vm.box = "ubuntu/bionic64" config.vm.provision :shell, path: "bootstrap.sh" config.vm.network :forwarded_port, guest: 80, host: 4567 end
|
关闭相关
1 2 3
| vagrant suspend vagrant halt vagrant destory
|