docker swarm集群操作

1.查看集群信息

[root@manager ~]# docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
4tlp5w6pbuhbw1vdm5eyfgvht *   manager             Ready               Active              Leader              19.03.8
l01337gajltyxxcj4u877zzfm     worker1             Ready               Active                                  19.03.8
sfecygd6gj6vlw6luivury2bp     worker2             Ready               Active                                  19.03.8

2.创建service

[root@manager ~]# docker service create  --name=web --replicas=3 -p 80:80 --detach=true --constraint 'node.role == worker'  --mount type=bind,src=/var/log,dst=/opt/ nginx
rw57fannzhjacrkt7pq22dooh

3.伸缩(可以引申重启,将副本数改成0 再改回来)

[root@manager ~]# docker service scale web=4
web scaled to 4
overall progress: 4 out of 4 tasks 
1/4: running   [==================================================>] 
2/4: running   [==================================================>] 
3/4: running   [==================================================>] 
4/4: running   [==================================================>] 

4.查看service详情

[root@manager ~]# docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                        PORTS
ve0exl9qcqmy        dev-portainer       replicated          1/1                 portainer/portainer:latest   *:9000->9000/tcp
a7w5urbvjz5a        web                 replicated          4/4                 nginx:latest                 *:80->80/tcp
[root@manager ~]# docker service inspect web
[
    {
        "ID": "a7w5urbvjz5amhocvx0n8enh8",
        "Version": {
            "Index": 3012
        },
        "CreatedAt": "2020-07-07T01:54:34.31118329Z",
        "UpdatedAt": "2020-07-07T01:54:57.198738506Z",
        "Spec": {
            "Name": "web",
            "Labels": {},
            "TaskTemplate": {
                "ContainerSpec": {
                    "Image": "nginx:latest@sha256:21f32f6c08406306d822a0e6e8b7dc81f53f336570e852e25fbe1e3e3d0d0133",
                    "Init": false,
。。。。。。。。。。。。。。

5.删除

[root@manager ~]# docker service rm web
web

 

posted @ 2020-07-07 09:55  caonw  阅读(342)  评论(0编辑  收藏  举报