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