4.1 Docker网络之搭建实验环境

搭建两台虚拟机,这两台虚拟机可以互相ping通,也能够与宿主机互相ping通。Vagrantfile的配置如下:

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 1.6.0"
boxes = [
    {
        :name => "docker-node1",
        :eth1 => "192.168.205.10",
        :mem => "1024",
        :cpu => "1"
    },
    {
        :name => "docker-node2",
        :eth1 => "192.168.205.11",
        :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 "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", :nfs => true
  config.vm.provision "shell", privileged: true, path: "./setup.sh"
end

其中,setup.sh的内容如下

#!/usr/bin/env bash
#/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 usermod -aG docker vagrant
sudo systemctl start docker
rm -rf get-docker.sh

你可能感兴趣的:(docker)