github.com/khulnasoft/cli@v0.0.0-20240402070845-01bcad7beefa/docs/extend/plugins_services.md (about) 1 --- 2 keywords: "API, Usage, plugins, documentation, developer" 3 title: Plugins and Services 4 --- 5 6 <!-- This file is maintained within the docker/cli GitHub 7 repository at https://github.com/khulnasoft/cli/. Make all 8 pull requests against that repo. If you see this file in 9 another repository, consider it read-only there, as it will 10 periodically be overwritten by the definitive file. Pull 11 requests which include edits to this file in other repositories 12 will be rejected. 13 --> 14 15 # Using Volume and Network plugins in Docker services 16 17 In swarm mode, it is possible to create a service that allows for attaching 18 to networks or mounting volumes that are backed by plugins. Swarm schedules 19 services based on plugin availability on a node. 20 21 22 ### Volume plugins 23 24 In this example, a volume plugin is installed on a swarm worker and a volume 25 is created using the plugin. In the manager, a service is created with the 26 relevant mount options. It can be observed that the service is scheduled to 27 run on the worker node with the said volume plugin and volume. Note that, 28 node1 is the manager and node2 is the worker. 29 30 1. Prepare manager. In node 1: 31 32 ```console 33 $ docker swarm init 34 Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager. 35 ``` 36 37 2. Join swarm, install plugin and create volume on worker. In node 2: 38 39 ```console 40 $ docker swarm join \ 41 --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \ 42 192.168.99.100:2377 43 ``` 44 45 ```console 46 $ docker plugin install tiborvass/sample-volume-plugin 47 latest: Pulling from tiborvass/sample-volume-plugin 48 eb9c16fbdc53: Download complete 49 Digest: sha256:00b42de88f3a3e0342e7b35fa62394b0a9ceb54d37f4c50be5d3167899994639 50 Status: Downloaded newer image for tiborvass/sample-volume-plugin:latest 51 Installed plugin tiborvass/sample-volume-plugin 52 ``` 53 54 ```console 55 $ docker volume create -d tiborvass/sample-volume-plugin --name pluginVol 56 ``` 57 58 3. Create a service using the plugin and volume. In node1: 59 60 ```console 61 $ docker service create --name my-service --mount type=volume,volume-driver=tiborvass/sample-volume-plugin,source=pluginVol,destination=/tmp busybox top 62 63 $ docker service ls 64 z1sj8bb8jnfn my-service replicated 1/1 busybox:latest 65 ``` 66 67 `docker service ls` shows service 1 instance of service running. 68 69 4. Observe the task getting scheduled in node 2: 70 71 ```console 72 $ docker ps --format '{{.ID}}\t {{.Status}} {{.Names}} {{.Command}}' 73 83fc1e842599 Up 2 days my-service.1.9jn59qzn7nbc3m0zt1hij12xs "top" 74 ``` 75 76 ### Network plugins 77 78 In this example, a global scope network plugin is installed on both the 79 swarm manager and worker. A service is created with replicated instances 80 using the installed plugin. We will observe how the availability of the 81 plugin determines network creation and container scheduling. 82 83 Note that node1 is the manager and node2 is the worker. 84 85 86 1. Install a global scoped network plugin on both manager and worker. On node1 87 and node2: 88 89 ```console 90 $ docker plugin install bboreham/weave2 91 Plugin "bboreham/weave2" is requesting the following privileges: 92 - network: [host] 93 - capabilities: [CAP_SYS_ADMIN CAP_NET_ADMIN] 94 Do you grant the above permissions? [y/N] y 95 latest: Pulling from bboreham/weave2 96 7718f575adf7: Download complete 97 Digest: sha256:2780330cc15644b60809637ee8bd68b4c85c893d973cb17f2981aabfadfb6d72 98 Status: Downloaded newer image for bboreham/weave2:latest 99 Installed plugin bboreham/weave2 100 ``` 101 102 2. Create a network using plugin on manager. On node1: 103 104 ```console 105 $ docker network create --driver=bboreham/weave2:latest globalnet 106 107 $ docker network ls 108 NETWORK ID NAME DRIVER SCOPE 109 qlj7ueteg6ly globalnet bboreham/weave2:latest swarm 110 ``` 111 112 3. Create a service on the manager and have replicas set to 8. Observe that 113 containers get scheduled on both manager and worker. 114 115 On node 1: 116 117 ```console 118 $ docker service create --network globalnet --name myservice --replicas=8 mrjana/simpleweb simpleweb 119 w90drnfzw85nygbie9kb89vpa 120 ``` 121 122 ```console 123 $ docker ps 124 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 125 87520965206a mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4 "simpleweb" 5 seconds ago Up 4 seconds myservice.4.ytdzpktmwor82zjxkh118uf1v 126 15e24de0f7aa mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4 "simpleweb" 5 seconds ago Up 4 seconds myservice.2.kh7a9n3iauq759q9mtxyfs9hp 127 c8c8f0144cdc mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4 "simpleweb" 5 seconds ago Up 4 seconds myservice.6.sjhpj5gr3xt33e3u2jycoj195 128 2e8e4b2c5c08 mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4 "simpleweb" 5 seconds ago Up 4 seconds myservice.8.2z29zowsghx66u2velublwmrh 129 ``` 130 131 On node 2: 132 133 ```console 134 $ docker ps 135 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 136 53c0ae7c1dae mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4 "simpleweb" 2 seconds ago Up Less than a second myservice.7.x44tvvdm3iwkt9kif35f7ykz1 137 9b56c627fee0 mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4 "simpleweb" 2 seconds ago Up Less than a second myservice.1.x7n1rm6lltw5gja3ueikze57q 138 d4f5927ba52c mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4 "simpleweb" 2 seconds ago Up 1 second myservice.5.i97bfo9uc6oe42lymafs9rz6k 139 478c0d395bd7 mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4 "simpleweb" 2 seconds ago Up Less than a second myservice.3.yr7nkffa48lff1vrl2r1m1ucs 140 ``` 141 142 4. Scale down the number of instances. On node1: 143 144 ```console 145 $ docker service scale myservice=0 146 myservice scaled to 0 147 ``` 148 149 5. Disable and uninstall the plugin on the worker. On node2: 150 151 ```console 152 $ docker plugin rm -f bboreham/weave2 153 bboreham/weave2 154 ``` 155 156 6. Scale up the number of instances again. Observe that all containers are 157 scheduled on the master and not on the worker, because the plugin is not available on the worker anymore. 158 159 On node 1: 160 161 ```console 162 $ docker service scale myservice=8 163 myservice scaled to 8 164 ``` 165 166 ```console 167 $ docker ps 168 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 169 cf4b0ec2415e mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4 "simpleweb" 39 seconds ago Up 36 seconds myservice.3.r7p5o208jmlzpcbm2ytl3q6n1 170 57c64a6a2b88 mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4 "simpleweb" 39 seconds ago Up 36 seconds myservice.4.dwoezsbb02ccstkhlqjy2xe7h 171 3ac68cc4e7b8 mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4 "simpleweb" 39 seconds ago Up 35 seconds myservice.5.zx4ezdrm2nwxzkrwnxthv0284 172 006c3cb318fc mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4 "simpleweb" 39 seconds ago Up 36 seconds myservice.8.q0e3umt19y3h3gzo1ty336k5r 173 dd2ffebde435 mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4 "simpleweb" 39 seconds ago Up 36 seconds myservice.7.a77y3u22prjipnrjg7vzpv3ba 174 a86c74d8b84b mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4 "simpleweb" 39 seconds ago Up 36 seconds myservice.6.z9nbn14bagitwol1biveeygl7 175 2846a7850ba0 mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4 "simpleweb" 39 seconds ago Up 37 seconds myservice.2.ypufz2eh9fyhppgb89g8wtj76 176 e2ec01efcd8a mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4 "simpleweb" 39 seconds ago Up 38 seconds myservice.1.8w7c4ttzr6zcb9sjsqyhwp3yl 177 ``` 178 179 On node 2: 180 181 ```console 182 $ docker ps 183 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 184 ```