github.com/xeptore/docker-cli@v20.10.14+incompatible/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/docker/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      {% raw %}
    73      $ docker ps --format '{{.ID}}\t {{.Status}} {{.Names}} {{.Command}}'
    74      83fc1e842599     Up 2 days my-service.1.9jn59qzn7nbc3m0zt1hij12xs "top"
    75      {% endraw %}
    76      ```
    77  
    78  ### Network plugins
    79  
    80  In this example, a global scope network plugin is installed on both the
    81  swarm manager and worker. A service is created with replicated instances
    82  using the installed plugin. We will observe how the availability of the
    83  plugin determines network creation and container scheduling.
    84  
    85  Note that node1 is the manager and node2 is the worker.
    86  
    87  
    88  1. Install a global scoped network plugin on both manager and worker. On node1
    89     and node2:
    90  
    91      ```console
    92      $ docker plugin install bboreham/weave2
    93      Plugin "bboreham/weave2" is requesting the following privileges:
    94      - network: [host]
    95      - capabilities: [CAP_SYS_ADMIN CAP_NET_ADMIN]
    96      Do you grant the above permissions? [y/N] y
    97      latest: Pulling from bboreham/weave2
    98      7718f575adf7: Download complete
    99      Digest: sha256:2780330cc15644b60809637ee8bd68b4c85c893d973cb17f2981aabfadfb6d72
   100      Status: Downloaded newer image for bboreham/weave2:latest
   101      Installed plugin bboreham/weave2
   102      ```
   103  
   104  2. Create a network using plugin on manager. On node1:
   105  
   106      ```console
   107      $ docker network create --driver=bboreham/weave2:latest globalnet
   108  
   109      $ docker network ls
   110      NETWORK ID          NAME                DRIVER                   SCOPE
   111      qlj7ueteg6ly        globalnet           bboreham/weave2:latest   swarm
   112      ```
   113  
   114  3. Create a service on the manager and have replicas set to 8. Observe that
   115  containers get scheduled on both manager and worker.
   116  
   117      On node 1:
   118  
   119      ```console
   120      $ docker service create --network globalnet --name myservice --replicas=8 mrjana/simpleweb simpleweb
   121  w90drnfzw85nygbie9kb89vpa
   122      ```
   123  
   124      ```console
   125      $ docker ps
   126      CONTAINER ID        IMAGE                                                                                      COMMAND             CREATED             STATUS              PORTS               NAMES
   127      87520965206a        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         5 seconds ago       Up 4 seconds                            myservice.4.ytdzpktmwor82zjxkh118uf1v
   128      15e24de0f7aa        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         5 seconds ago       Up 4 seconds                            myservice.2.kh7a9n3iauq759q9mtxyfs9hp
   129      c8c8f0144cdc        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         5 seconds ago       Up 4 seconds                            myservice.6.sjhpj5gr3xt33e3u2jycoj195
   130      2e8e4b2c5c08        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         5 seconds ago       Up 4 seconds                            myservice.8.2z29zowsghx66u2velublwmrh
   131      ```
   132  
   133      On node 2:
   134  
   135      ```console
   136      $ docker ps
   137      CONTAINER ID        IMAGE                                                                                      COMMAND             CREATED             STATUS                  PORTS               NAMES
   138      53c0ae7c1dae        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         2 seconds ago       Up Less than a second                       myservice.7.x44tvvdm3iwkt9kif35f7ykz1
   139      9b56c627fee0        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         2 seconds ago       Up Less than a second                       myservice.1.x7n1rm6lltw5gja3ueikze57q
   140      d4f5927ba52c        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         2 seconds ago       Up 1 second                                 myservice.5.i97bfo9uc6oe42lymafs9rz6k
   141      478c0d395bd7        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         2 seconds ago       Up Less than a second                       myservice.3.yr7nkffa48lff1vrl2r1m1ucs
   142      ```
   143  
   144  4. Scale down the number of instances. On node1:
   145  
   146      ```console
   147      $ docker service scale myservice=0
   148      myservice scaled to 0
   149      ```
   150  
   151  5. Disable and uninstall the plugin on the worker. On node2:
   152  
   153      ```console
   154      $ docker plugin rm -f bboreham/weave2
   155      bboreham/weave2
   156      ```
   157  
   158  6. Scale up the number of instances again. Observe that all containers are
   159  scheduled on the master and not on the worker, because the plugin is not available on the worker anymore.
   160  
   161      On node 1:
   162  
   163      ```console
   164      $ docker service scale myservice=8
   165      myservice scaled to 8
   166      ```
   167  
   168      ```console
   169      $ docker ps
   170      CONTAINER ID        IMAGE                                                                                      COMMAND             CREATED             STATUS              PORTS               NAMES
   171      cf4b0ec2415e        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         39 seconds ago      Up 36 seconds                           myservice.3.r7p5o208jmlzpcbm2ytl3q6n1
   172      57c64a6a2b88        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         39 seconds ago      Up 36 seconds                           myservice.4.dwoezsbb02ccstkhlqjy2xe7h
   173      3ac68cc4e7b8        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         39 seconds ago      Up 35 seconds                           myservice.5.zx4ezdrm2nwxzkrwnxthv0284
   174      006c3cb318fc        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         39 seconds ago      Up 36 seconds                           myservice.8.q0e3umt19y3h3gzo1ty336k5r
   175      dd2ffebde435        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         39 seconds ago      Up 36 seconds                           myservice.7.a77y3u22prjipnrjg7vzpv3ba
   176      a86c74d8b84b        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         39 seconds ago      Up 36 seconds                           myservice.6.z9nbn14bagitwol1biveeygl7
   177      2846a7850ba0        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         39 seconds ago      Up 37 seconds                           myservice.2.ypufz2eh9fyhppgb89g8wtj76
   178      e2ec01efcd8a        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         39 seconds ago      Up 38 seconds                           myservice.1.8w7c4ttzr6zcb9sjsqyhwp3yl
   179      ```
   180  
   181      On node 2:
   182  
   183      ```console
   184      $ docker ps
   185      CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
   186      ```