*1,先在电脑里创一个文件夹
*然后把你的centos-7.0-x86_64.box拷过来,cmd
vagrant box add centos7 centos-7.0-x86_64.box
vagrant init centos7
生成vagrantfile文件
然后把那个修改一下
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 1.6.0"
boxes = [
{
:name => "swarm-manager",
:eth1 => "192.168.205.10",
:mem => "1024",
:cpu => "1"
},
{
:name => "swarm-worker1",
:eth1 => "192.168.205.11",
:mem => "1024",
:cpu => "1"
},
{
:name => "swarm-worker2",
:eth1 => "192.168.205.12",
:mem => "1024",
:cpu => "1"
}
]
Vagrant.configure(2) do |config|
config.vm.box = "centos/7"
boxes.each do |opts|
config.vm.define opts[:name] do |config|
config.vm.hostname = opts[:name]
config.vm.provider "vmware_fusion" do |v|
v.vmx["memsize"] = opts[:mem]
v.vmx["numvcpus"] = opts[:cpu]
end
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", opts[:mem]]
v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
end
config.vm.network :private_network, ip: opts[:eth1]
end
end
config.vm.provision "shell", privileged: true, path: "./setup.sh"
end
再创一个setup.sh的脚本
#/bin/sh
# install some tools
sudo yum install -y git vim gcc glibc-static telnet bridge-utils
# install docker
curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh
# start docker service
sudo groupadd docker
sudo gpasswd -a vagrant docker
sudo systemctl start docker
rm -rf get-docker.sh
然后在cmd里vagrant up等待三个虚拟机打开,打开之后cmd打开三个虚拟机
在主虚拟机里 docker swarm init
然后选择中间那一行
三个都输一遍
最后用 docker node ls查看
成功!