Server1(Server) 192.168.81.58 內核版本 3.10.0-123.el7.x86_64 Docker版本 1.12.6
Server2(Agent) 192.168.81.59 3.10.0-123.el7.x86_64 1.12.6
實驗目標:兩個CentOS7容器server1,server2網絡互通
上傳docker_consul包 consul_0.7.2_linux_amd64.zip
解壓consul並移動到$PATH中
unzip consul_0.7.2_linux_amd64.zip -d /usr/local/bin
Server1:
mkdir /opt/d_c
nohup consul agent -server -bootstrap -data-dir /opt/d_c -bind=192.168.81.58 &
顯示結果:nohup: ignoring input and appending output to ‘nohup.out’
Server2:
mkdir /opt/d_c
nohup consul agent -data-dir /opt/d_c -bind=192.168.81.59 &
顯示結果:nohup: ignoring input and appending output to ‘nohup.out’
讓agent加入到server中
consul join 192.168.81.58
顯示結果:Successfully joined cluster by contacting 1 nodes.
vim /etc/sysconfig/docker-network
DOCKER_NETWORK_OPTIONS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store consul://localhost:8500 --cluster-advertise eno16777736:2375"
service docker restart
docker network ls
顯示結果包含:multihost overlay global
查看Docker網絡內的成員
consul members list
Server1:
docker run -d --net=multihost --name=web1 nginx
docker exec -it web1 /bin/bash
Server2:
docker run -d --net=multihost --name=web2 nginx
docker exec -it web2 /bin/bash
ping web1
ping web2
創建指定靜態IP的network
docker network create -d overlay --ip-range=192.168.2.0/24 --gateway=192.168.2.1 --subnet=192.168.2.0/24 multihost2

