李明
|
单机
多机
编辑多机Vagrantfile
# -*- mode: ruby -*-# vi: set ft=ruby :Vagrant.require_version ">= 1.6.0"boxes = [ { :name => "docker-node1", :mem => "1024", :cpu => "1" }, { :name => "docker-node2", :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, type: "dhcp" end end config.vm.synced_folder "./labs", "/home/vagrant/labs" config.vm.provision "shell", privileged: true, path: "./setup.sh"end
vagrant up
vagrant ssh docker-node1ifconfig
vagrant ssh docker-node2ifconfig
#不通的机器可能ip不相同,这个问题,根据查看得来的ping 172.28.128.3ping 172.28.128.4
PS:本机基本上docker的多虚拟机网络已经完成了,比较简单,毕竟是演示环境,可能有老铁说,为啥设置成了自动获得IP,而不是静态IP,毕竟是学习的环境,我也尝试改成过静态IP但是ping不通,其实我的思路就是先让计算机帮我设置一个自动获取的IP,我可以在他的基础上设置自己的静态ip,这样保证可以用,对于静态IP如何设置我也写一份静态IP的配置吧,跟上边差距不太大。 还有老铁说 我不太习惯用vagrant 我喜欢用docker-machine,这个都无所谓了,其实重点是吧环境搭建起来。 #静态版本的。# -*- mode: ruby -*-# vi: set ft=ruby :Vagrant.require_version ">= 1.6.0"boxes = [ { :name => "docker-node1", :mem => "1024", :eth1=>"172.28.128.3", :cpu => "1" }, { :name => "docker-node2", :mem => "1024", :eth1=>"172.28.128.4", :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.synced_folder "./labs", "/home/vagrant/labs" config.vm.provision "shell", privileged: true, path: "./setup.sh"end
|
2018-09-06 10:23:32