Skip to content

Instantly share code, notes, and snippets.

@philipz
Last active January 22, 2017 01:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save philipz/5c84b40e35fa166dd9f72cfd62bc3335 to your computer and use it in GitHub Desktop.
Save philipz/5c84b40e35fa166dd9f72cfd62bc3335 to your computer and use it in GitHub Desktop.
Prepare Docker Swarm Environment

#On Local Machine Side ##Install Docker Engine && Docker Machine ###Docker Engine sudo wget -qO- http://get.docker.com/ | sh ###Docker Machine Docker Machine Github

wget https://github.com/docker/machine/releases/download/v0.8.0/docker-machine-`uname -s`-`uname -m` && \
sudo mv docker-machine-`uname -s`-`uname -m` /usr/local/bin/docker-machine && \
sudo chmod +x /usr/local/bin/docker-machine

##Use Docker Machine to create VM ###For Azure

  1. 如何取得 Subscription ID

On Linux/Mac, or Windows,上傳 Cert 到 Azure Portal,取得 Subscription ID。

  1. 建立 Azure VM

docker-machine create -d azure --azure-subscription-id="XXX" --azure-location="eastasia" docker-00-node01

docker-machine create -d azure --azure-subscription-id="XXX" --azure-location="eastasia" --engine-install-url https://test.docker.com docker-00-node02

docker-machine create -d azure --azure-subscription-id="XXX" --azure-location="eastasia" --azure-image canonical:ubuntuserver:16.04.0-LTS:16.04.201608150 --azure-size Standard_A1 --engine-install-url https://get.docker.com docker-00-node01

docker-machine ssh docker-00-node01 sudo usermod -aG docker docker-user

參考文件:

Docker Machine Azure Docs

使用 Docker 電腦搭配 Azure 驅動程式

###For VMware docker-machine create node-01 --driver vmwarevsphere --vmwarevsphere-datacenter ha-datacenter --vmwarevsphere-vcenter 192.168.2.12 --vmwarevsphere-username root --vmwarevsphere-password PASSWORD --vmwarevsphere-datastore 1TB --vmwarevsphere-network "VM Network" Azure Docs

##Create a swarm cluster Old style: Get started with multi-host networking

New style: Swarm Docs, Swarm Tutorial ###First Manager docker swarm init --advertise-addr eth0:2377 --listen-addr 0.0.0.0:2377

To add a worker to this swarm, run the following command:
    docker swarm join \
    --token SWMTKN-1-3xv0lszxmfary0gob9juhrvjrw1kgnau3qcee2tmdqdepc28vb-4qaycizk63r1sdgv61r72mxyu \
    192.168.0.4:2377

To add a manager to this swarm, run the following command:
    docker swarm join \
    --token SWMTKN-1-3xv0lszxmfary0gob9juhrvjrw1kgnau3qcee2tmdqdepc28vb-8ezacy1qzubgllmne9h1zovso \
    192.168.0.4:2377

###Second Manager docker swarm join --token $TOKEN_MASTER_STRING $MASTER1:2377 --listen-addr 0.0.0.0:2377

提醒最好要有三個 Manager ###First Worker docker swarm join --token $TOKEN_WORKER_STRING $MASTER1:2377 ###Second Worker docker swarm join --token $TOKEN_WORKER_STRING $MASTER2:2377

##Daemon labels

docker daemon \
  --dns 8.8.8.8 \
  --dns 8.8.4.4 \
  -H unix:///var/run/docker.sock \
  --label com.example.environment="production" \
  --label com.example.storage="ssd"

azure_firewall firewall complete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment