Step 1: Set up a key-value store
1、创建swarm的keystore宿主机,创建命令如下:
docker-machine create -d virtualbox mh-keystore
2、拉取keystore的consul镜像,相关命令如下:
docker-machine create -d virtualbox mh-keystore
docker run -d \
-p "8500:8500" \
-h "consul" \
progrium/consul -server -bootstrap
Step 2: Create a Swarm cluster
1、创建cluster的master节点,命令如下:
$ docker-machine create \
-d virtualbox \
--swarm --swarm-master \
--swarm-discovery="consul://$(docker-machine ip mh-keystore):8500" \
--engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500" \
--engine-opt="cluster-advertise=eth1:2376" \
mhs-demo0
2、创建cluster的普通节点,创建命令如下:
docker-machine create -d virtualbox \
--swarm \
--swarm-discovery="consul://$(docker-machine ip mh-keystore):8500" \
--engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500" \
--engine-opt="cluster-advertise=eth1:2376" \
mhs-demo1
Step 3: Create Composefile
version: '2'
services:
bms:
image: tomcat:8-jre8
volumes:
- /c/Users/xu/Desktop/composetest/:/usr/local/tomcat/webapps
ports:
- "8888:8080"
networks:
- frontend
depends_on:
- mymysql
environment:
- "constraint:node==mh-demo1"
mymysql:
image: mysql:latest
volumes:
- /c/Users/xu/Desktop/composetest/mysqldata/:/usr/lib/mysql
ports:
- "3306:3306"
networks:
- frontend
environment:
- "constraint:node==mh-demo0"
- MYSQL_ROOT_PASSWORD=123456
networks:
frontend:
Step 4: Up Compose
eval $(docker-machine env --swarm mhsdemo0)
docker-compose up