本文共 8966 字,大约阅读时间需要 29 分钟。
curl -Lo /usr/bin/docker.exe https://get.docker.com/builds/Windows/x86_64/docker-1.10.3.exe下载docker-machine的Windows 64位二进制(包括hyperv驱动)
curl -Lo /usr/bin/docker-machine.exe https://github.com/docker/machine/releases/download/v0.6.0/docker-machine-Windows-x86_64.exe下载docker-compose的Windows 64位二进制
curl -Lo /usr/bin/docker-compose.exe https://github.com/docker/compose/releases/download/1.6.2/docker-compose-Windows-x86_64.exe
$env:Path.Contains("$env:LOCALAPPDATA\Programs\Git\usr\bin")应当返回True。 确认Docker工具在工作:
docker --version; docker-machine --version; docker-compose --version应当返回类似下面的内容:
Docker version 1.10.3, build 20f81dddocker-machine.exe version 0.6.0, build e27fb87docker-compose version 1.6.2, build e80fc83在这篇指导中,我们使用以下别名:
New-Alias "dm" "docker-machine"
docker-machine create consul0在PowerShell中使用Hyper-V并设置自定义内存:
dm create `--driver hyperv `--hyperv-virtual-switch "VMware NAT" `--hyperv-memory "512" consul0
192.168.233.0/24
子网,NAT网关在192.168233.2
,DHCP范围是128-254
。我们将指定192.168.233.10
作为我们Consul结点的静态IP。记住你需要更新这些值来符合你的配置。 默认情况下,DHCP在Boot2Docker接口上是打开的,但是我们需要关闭它,通过杀死管理这个接口的进程:kill `more /var/run/udhcpc.eth0.pid`先不要在Boot2Docker虚拟机上运行下列命令,我们需要在之后的步骤把它们加入到启动进程。 为了设置一个静态IP并且保证有一个到网关的默认路由,我们使用下列两个命令:
ifconfig eth0 192.168.233.10 netmask 255.255.255.0 broadcast 192.168.233.255 uproute add default gw 192.168.233.2(译者注:这里为何不直接配置/etc/networking/interfaces?匪夷所思。) 如果我们不使用PowerShell,我们可以添加上面的命令作为启动脚本像下面这样:
cat <<"EOF" | sudo tee /var/lib/boot2docker/bootsync.shkill `more /var/run/udhcpc.eth0.pid`ifconfig eth0 192.168.233.10 netmask 255.255.255.0 broadcast 192.168.233.255 uproute add default gw 192.168.233.2EOF或者使用PowerShell在宿主上执行一条命令
echo "kill ``more /var/run/udhcpc.eth0.pid```n`ifconfig eth0 192.168.233.10 netmask 255.255.255.0 broadcast 192.168.233.255 up`n`route add default gw 192.168.233.2" | `dm ssh consul0 "sudo tee /var/lib/boot2docker/bootsync.sh" > $null接下来
dm restart consul0
dm regenerate-certs consul0
docker-machine env consul0在PowerShell中激活这个环境(使用iex作为Invoke-Expression的别名),像下面这样:
dm env consul0 | iex确定全部工作正常
docker info启动一个单结点的Consul容器,暴露它的DNS和Consul API
docker run -d -p 192.168.233.10:8500:8500 -p 192.168.233.10:53:8600/udp --name consul -h consul --restart always gliderlabs/consul-server -bootstrap跟随你的Consul结点的启动进程:
docker logs -f consul按下CTRL+C并且添加一个静态的consul IP的记录到你的宿主hosts文件中(如果你的虚拟网络转发DNS查询到你的宿主机,这会允许所有你的结点通过consul0的主机名指向consul结点。
"consul0" | `% { "$($(Get-VM $_).NetworkAdapters[0].IpAddresses[0]) $_" } | `ac $env:Windir\System32\Drivers\etc\hosts确定Consul工作:
iwr http://consul0:8500/v1/catalog/nodes | ConvertFrom-Json
dm create `--driver hyperv `--hyperv-virtual-switch "VMware NAT" `--swarm --swarm-master `--swarm-discovery "consul://consul0:8500/cluster1" `--engine-opt "cluster-store consul://consul0:8500" `--engine-opt "cluster-advertise eth0:2376" `--engine-opt "cluster-store-opt kv.path=cluster1/docker/overlay" master0
/var/lib/boot2docker/profile
来确定引擎参数 dm ssh master0 cat /var/lib/boot2docker/profile
iwr http://consul0:8500/v1/kv/?recurse | ConvertFrom-Json | ft Key
dm create `--driver hyperv `--hyperv-virtual-switch "VMware NAT"`--swarm `--swarm-discovery="consul://consul0:8500/cluster1" `--engine-opt="cluster-store=consul://consul0:8500" `--engine-opt="cluster-advertise=eth0:2376" `--engine-opt="cluster-store-opt=kv.path=cluster1/docker/overlay" `--engine-label="com.docker-saigon.group=frontend" `--engine-label "com.docker-saigon.environment=dev" node0
iwr http://consul0:8500/v1/kv/?recurse | ConvertFrom-Json | ft Key
dm env --swarm master0 | iex
dm ssh node0
curl -Lo docker-volume-netshare_0.11.tar.gz https://dl.bintray.com//content/pacesys/docker/docker-volume-netshare_0.11_linux_amd64.tar.gz?direct
sudo tar -xf docker-volume-netshare_0.11.tar.gz -C /var/lib/boot2docker/ --strip=1 docker-volume-netshare_0.11_linux_amd64/docker-volume-netshare \&& rm -f docker-volume-netshare_0.11.tar.gz
sudo sh -c 'cat > /var/lib/boot2docker/.netrc <
echo '/var/lib/boot2docker/docker-volume-netshare cifs --netrc /var/lib/boot2docker >/var/lib/boot2docker/log/netshare 2>&1 /dev/null
dm ssh node0 ps xawu | grep netshare
dm env --swarm master0 | iex
docker network ls
docker network create --subnet=10.0.10.0/24 nw
docker network ls
docker pull alpine
CTRL+SHIFT+O
来水平分割控制台 New-Alias dm docker-machinedm env --swarm master0 | iex
node0
上的netshare的日志: dm ssh node0 tail -f /var/lib/boot2docker/log/netshare
docker volume create -d cifs --name /192.168.233.1/demo
docker run -dit --name container1 --net nw -v 192.168.233.1/demo:/demo alpine sh
docker run -dit --name container2 --net nw -v 192.168.233.1/demo:/demo alpine sh
spread
调度策略,每一个容器运行在一个单独的结点上: docker ps
docker exec -it container1 ping container2
docker exec -it container1 touch /demo/fromcontainer1
docker exec -it container2 ls -l /demo/
Get-VM | ? { $_.State -eq "Running" }
Get-VM | ? { $_.State -eq "Running" } | select Name, Uptime, @{l="IpAddress";e={$_.NetworkAdapters[0].IpAddresses[0]}}
$vm = Get-VM consul0vmconnect $env:COMPUTERNAME $vm.Name -G $vm.Id
Add-Content
命令来作为/etc/hosts): "master0","node0","node1" | % { "$($(Get-VM $_).NetworkAdapters[0].IpAddresses[0]) $_ " }
转载地址:http://jkoao.baihongyu.com/