$ docker run swarm create
c745d2d1bd2f65579e41f3808533da86
接下來複製上面產生的 Token,後面要用到
先建立 swarm-master
1
2
3
4
5
6
7
$ docker-machine create -d virtualbox --swarm --swarm-master --swarm-discovery token://c745d2d1bd2f65579e41f3808533da86 swarm-master
INFO[0000] Creating SSH key...
INFO[0000] Creating VirtualBox VM...
INFO[0010] Starting VirtualBox VM...
INFO[0010] Waiting for VM to start...
INFO[0087]"swarm-master" has been created and is now the active machine.
INFO[0087] To point your Docker client at it, run this in your shell: docker-machine env swarm-master | source
接下來分別建立 swarm-node01, swarm-node02
1
2
3
4
5
6
7
$ docker-machine create -d virtualbox --swarm --swarm-discovery token://c745d2d1bd2f65579e41f3808533da86 swarm-node-01
INFO[0000] Creating SSH key...
INFO[0000] Creating VirtualBox VM...
INFO[0010] Starting VirtualBox VM...
INFO[0011] Waiting for VM to start...
INFO[0073]"swarm-node-01" has been created and is now the active machine.
INFO[0073] To point your Docker client at it, run this in your shell: docker-machine env swarm-node-01 | source
1
2
3
4
5
6
7
$ docker-machine create -d virtualbox --swarm --swarm-discovery token://c745d2d1bd2f65579e41f3808533da86 swarm-node-02
INFO[0000] Creating SSH key...
INFO[0000] Creating VirtualBox VM...
INFO[0010] Starting VirtualBox VM...
INFO[0011] Waiting for VM to start...
INFO[0070]"swarm-node-02" has been created and is now the active machine.
INFO[0070] To point your Docker client at it, run this in your shell: docker-machine env swarm-node-02 | source
執行後的結果
1
2
3
4
5
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
swarm-master virtualbox Running tcp://192.168.99.102:2376 swarm-master (master)swarm-node-01 virtualbox Running tcp://192.168.99.103:2376 swarm-master
swarm-node-02 * virtualbox Running tcp://192.168.99.104:2376 swarm-master
看一下 swarm-master 裡面,跑了什麼東西
如果發現,執行 docker ps 沒東西,表示你現在並非在 swarm-master
先執行一下 docker-machine active swarm-master 就可以