description | keywords | title |
---|---|---|
Setup for voting app example |
multi-container, services, swarm mode, cluster, voting app |
Create a swarm |
Now, we'll add our Docker machines to a swarm.
-
Log into the manager.
$ docker-machine ssh manager ## . ## ## ## == ## ## ## ## ## === /"""""""""""""""""\___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\_______/ _ _ ____ _ _ | |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __ | '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__| | |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ | |_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_| WARNING: this is a build from test.docker.com, not a stable release. Boot2Docker version 1.13.0-rc7, build HEAD : b2cde29 - Sat Jan 14 00:29:39 UTC 2017 Docker version 1.13.0-rc7, build 48a9e53
-
Initialize a swarm.
The command to initialize a swarm is:
docker swarm init --advertise-addr <MANAGER-IP>
Tip: To get the IP address of the manager, use a terminal window that is not
ssh
'ed into a virtual machine (or exit out of a current one), and type eitherdocker-machine ip manager
ordocker-machine ls
. Look back at Verify machines are running and get IP addresses) for examples.docker@manager:~$ docker swarm init --advertise-addr 192.168.99.100 Swarm initialized: current node (2tjrasfqfu945b7n4753374sw) is now a manager. To add a worker to this swarm, run the following command: docker swarm join \ --token SWMTKN-1-144pfsupfo25h43zzr6b6bghjson8uedxjsndo5vuehqlyarsk-9k4q84axm008whv9zl4a8m8ct \ 192.168.99.100:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
Tip: The next step is to log into the worker machine. You can either open a new shell, or exit out of the manager in the current shell by typing
exit
.
-
Log into the worker machine.
$ docker-machine ssh worker ## . ## ## ## == ## ## ## ## ## === /"""""""""""""""""\___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\_______/ _ _ ____ _ _ | |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __ | '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__| | |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ | |_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_| WARNING: this is a build from test.docker.com, not a stable release. Boot2Docker version 1.13.0-rc7, build HEAD : b2cde29 - Sat Jan 14 00:29:39 UTC 2017 Docker version 1.13.0-rc7, build 48a9e53
-
On the worker, run the
join
command given as the output of theswarm init
command you ran on the manager.docker@worker:~$ docker swarm join \ > --token SWMTKN-1-144pfsupfo25h43zzr6b6bghjson8uedxjsndo5vuehqlyarsk-9k4q84axm008whv9zl4a8m8ct \ > 192.168.99.100:2377 This node joined a swarm as a worker.
If you don't have the command, run
docker swarm join-token worker
on a manager node to retrieve thejoin
command for a worker for this swarm.
Log into the manager (e.g., docker-machine ssh manager
) and run docker node ls
.
docker@manager:~$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
2tjrasfqfu945b7n4753374sw * manager Ready Active Leader
syc46yimgtyz9ljcsfqiurvp0 worker Ready Active
In the next step, we'll deploy the voting app.