下载vagrant
# 方法一:命令行安装
brew install vagrant
# 方法二: 下载镜像安装
https://releases.hashicorp.com/vagrant/2.3.0/vagrant_2.3.0_darwin_amd64.dmg
下载vmware
根据系统选择安装的版本,其中macOS选择vmware fusion pro版本,其中一安装过程需要license,这里可以申请个人免费的,具体可以百度;二是需要在安全和隐私开启vmware的权限,教程链接
创建vagrant目录文件
mkdir -p ~/vagrant/centos7
# 切换到创建的目录中
cd ~/vagrant/centos7
# 创建镜像7
vagrant init centos/7
# 这个时候会有一个Vagrantfile文件
这里有个坑,就是macos搭建默认是virtualbox,所以使用vmware需要安装插件
# 安装插件
vagrant plugin install vagrant-vmware-desktop
# 安装Vagrant VMware Utility, 地址如下,安装方法和vmware的dmg镜像类似
https://www.vagrantup.com/vmware/downloads
# macos服务配置
sudo launchctl load -w /Library/LaunchDaemons/com.vagrant.vagrant-vmware-utility.plist
/opt/vagrant-vmware-desktop/bin/vagrant-vmware-utility service uninstall
/opt/vagrant-vmware-desktop/bin/vagrant-vmware-utility service install -port=9999
贴上本地的Vagrantfile配置文件
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.hostname = "docker-host"
# 设置共享目录
config.vm.synced_folder "/Users/xx/code", "/home/vagrant/code"
# 设置网络
#config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "public_network", ip: "192.168.10.10"
#vmware fusion provider
config.vm.provider "vmware_desktop" do |vm|
vm.vmx["memsize"] = "2048"
vm.vmx["numvcpus"] = "2"
end
config.vm.provision "shell", run: "once", inline: <<-SHELL
sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo groupadd docker
sudo gpasswd -a $USER docker
sudo systemctl start docker
SHELL
end
创建虚拟机
# 启动容器
vagrant up
# 进入容器
vagrant ssh
# 验证docker是否安装成功
docker --version
标签:macOS,安装,vagrant,vm,centos7,docker,config,vmware
From: https://www.cnblogs.com/simple-record/p/16600626.html