$ docker swarm init --listen-addr 192.168.99.100:2377
Swarm initialized: current node (09fm6su6c24qn) is now a manager.
查看节点:
123
$ docker node ls
ID NAME MEMBERSHIP STATUS AVAILABILITY MANAGER STATUS LEADER
09fm6su6c24q * manager1 Accepted Ready Active Reachable Yes
然后这样来部署一个新的service:
123456
$ docker service create --scale 1 --name helloworld alpine ping docker.com
2zs4helqu64f3k3iuwywbk49w
$ docker service ls
ID NAME SCALE IMAGE COMMAND
2zs4helqu64f helloworld 1 alpine ping docker.com
需要scale了?没关系,也可以在Docker中直接完成:
12345678910
$ docker service update --scale 5 helloworld
helloworld
$ docker service tasks helloworld
ID NAME SERVICE IMAGE DESIRED STATE LAST STATE NODE
1n6wif51j0w840udalgw6hphg helloworld.1 helloworld alpine RUNNING RUNNING 2 minutes manager1
dfhsosk00wxfb7j0cazp3fmhy helloworld.2 helloworld alpine RUNNING RUNNING 15 seconds worker2
6cbedbeywo076zn54fnwc667a helloworld.3 helloworld alpine RUNNING RUNNING 15 seconds worker1
7w80cafrry7asls96lm2tmwkz helloworld.4 helloworld alpine RUNNING RUNNING 10 seconds worker1
bn67kh76crn6du22ve2enqg5j helloworld.5 helloworld alpine RUNNING RUNNING 10 seconds manager1
在一台机器上使用 docker ps :
12345
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
910669d5e188 alpine:latest "ping docker.com" 10 seconds ago Up 10 seconds helloworld.5.bn67kh76crn6du22ve2enqg5j
a0b6c02868ca alpine:latest "ping docker.com" 2 minutes ago Up 2 minutes helloworld.1.1n6wif51j0w840udalgw6hphg
我们也可以这样使用 dcoekr service 子命令。
12345678
$ docker service create --scale 3 --name redis --update-delay 10s --update-parallelism 1 redis:3.0.6
69uh57k8o03jtqj9uvmteodbb
$ docker service tasks redis
ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE
3wfqsgxecktpwoyj2zjcrcn4r redis.1 redis redis:3.0.6 RUNNING 13 minutes RUNNING worker2
8lcm041z3v80w0gdkczbot0gg redis.2 redis redis:3.0.6 RUNNING 13 minutes RUNNING worker1
d48skceeph9lkz4nbttig1z4a redis.3 redis redis:3.0.6 RUNNING 12 minutes RUNNING manager1
这是一个大概的使用示意,通过 docker plugin install 可以安装插件, docker plugin ls 可以列出当前安装的插件:
12345
$ docker plugin install aragunathan/no-remove
Plugin "aragunathan/no-remove:latest" requested the following privileges:
- Networking: host
- Mounting host path: /data
Do you grant the above permissions? [y/N] y
查看插件列表:
123
$ docker plugin ls
NAME VERSION ACTIVE
aragunathan/no-remove latest true