使用Docker Machine建立Docker Swarm

建立consul server

consul server是kubernetes用來傳遞cluster資訊的,在cluster建立前,先準備好consul server...

# consul用的docker machine
docker-machine create \
  --driver google \
  --google-project sunny-573 \
  --google-zone asia-east1-a \
  --google-tags test \
  --google-machine-type f1-micro simon-keystore

# 啟動consul docker
docker $(docker-machine config simon-keystore) run -d \
  -p "8500:8500" \
  -h "consul" progrium/consul \
  -server -bootstrap

建立Swarm Master

docker-machine create \
--driver google \
--google-project $PROJECT \
--google-zone asia-east1-c \
--google-machine-type n1-standard-1 \
--google-machine-image projects/sunny-573/global/images/docker-default-v20160810 \
--swarm --swarm-master \
--swarm-discovery="consul://$(docker-machine ip simon-keystore):8500" \
--engine-opt="cluster-store=consul://$(docker-machine ip simon-keystore):8500" \
--engine-opt="cluster-advertise=eth0:2376" \
mhs-demo0

建立Swarm Slave Nodes

docker-machine create \
--driver google \
--google-project $PROJECT \
--google-zone asia-east1-c \
--google-machine-type n1-standard-1 \
--google-machine-image projects/$PROJECT/global/images/docker-default-v20160810 \
--swarm \
--swarm-discovery="consul://$(docker-machine ip simon-keystore):8500" \
--engine-opt="cluster-store=consul://$(docker-machine ip simon-keystore):8500" \
--engine-opt="cluster-advertise=eth0:2376" \
mhs-demo1

設定本地連線參數

eval `docker-machine env --swarm simon-mhs-demo0`

如果一切沒問題,那就測試一下咯...

# docker-compose -f iot-server.yml ps
           Name                       Command                       State                        Ports
-----------------------------------------------------------------------------------------------------------------
iot-build-controller         node build-controller        Up                           104.155.239.142:3330->3330
                                                                                       /tcp
iot-couchdb                  tini -- /docker-entrypoint   Up                           104.155.239.142:5984->5984
                             ...                                                       /tcp
iot-mongodb                  /entrypoint.sh mongod        Up                           104.155.194.86:27017->2701
                                                                                       7/tcp, 104.155.194.86:2801
                                                                                       7->28017/tcp
iot-server                   node server                  Up                           104.155.239.142:3000->3000
                                                                                       /tcp

參考

results matching ""

    No results matching ""