Browse code

Merge pull request #31071 from anusha-ragunathan/plugin_filter_network

Service creation using network plugin filters.

Anusha Ragunathan authored on 2017/02/28 04:59:11
Showing 2 changed files
... ...
@@ -118,63 +118,6 @@ remove it, use the `docker plugin remove` command. For other available
118 118
 commands and options, see the
119 119
 [command line reference](../reference/commandline/index.md).
120 120
 
121
-## Service creation using plugins
122
-
123
-In swarm mode, it is possible to create a service that allows for attaching
124
-to networks or mounting volumes. Swarm schedules services based on plugin availability
125
-on a node. In this example, a volume plugin is installed on a swarm worker and a volume
126
-is created using the plugin. In the manager, a service is created with the relevant
127
-mount options. It can be observed that the service is scheduled to run on the worker
128
-node with the said volume plugin and volume.
129
-
130
-In the following example, node1 is the manager and node2 is the worker.
131
-
132
-1.  Prepare manager. In node 1:
133
-
134
-    ```bash
135
-    $ docker swarm init
136
-    Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager.
137
-    ```
138
-
139
-2. Join swarm, install plugin and create volume on worker. In node 2:
140
-
141
-    ```bash
142
-    $ docker swarm join \
143
-    --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
144
-    192.168.99.100:2377
145
-    ```
146
-
147
-    ```bash
148
-    $ docker plugin install tiborvass/sample-volume-plugin
149
-    latest: Pulling from tiborvass/sample-volume-plugin
150
-    eb9c16fbdc53: Download complete
151
-    Digest: sha256:00b42de88f3a3e0342e7b35fa62394b0a9ceb54d37f4c50be5d3167899994639
152
-    Status: Downloaded newer image for tiborvass/sample-volume-plugin:latest
153
-    Installed plugin tiborvass/sample-volume-plugin
154
-    ```
155
-
156
-    ```bash
157
-    $ docker volume create -d tiborvass/sample-volume-plugin --name pluginVol
158
-    ```
159
-
160
-3. Create a service using the plugin and volume. In node1:
161
-
162
-    ```bash
163
-    $ docker service create --name my-service --mount type=volume,volume-driver=tiborvass/sample-volume-plugin,source=pluginVol,destination=/tmp busybox top
164
-
165
-    $ docker service ls
166
-    z1sj8bb8jnfn  my-service   replicated  1/1       busybox:latest
167
-    ```
168
-    docker service ls shows service 1 instance of service running.
169
-
170
-4. Observe the task getting scheduled in node 2:
171
-
172
-    ```bash
173
-    {% raw %}
174
-    $ docker ps --format '{{.ID}}\t {{.Status}} {{.Names}} {{.Command}}'
175
-    83fc1e842599     Up 2 days my-service.1.9jn59qzn7nbc3m0zt1hij12xs "top"
176
-    {% endraw %}
177
-    ```
178 121
 
179 122
 ## Developing a plugin
180 123
 
181 124
new file mode 100644
... ...
@@ -0,0 +1,184 @@
0
+---
1
+description: Using services with plugins
2
+keywords: "API, Usage, plugins, documentation, developer"
3
+title: Plugins and Services
4
+---
5
+
6
+<!-- This file is maintained within the docker/docker Github
7
+     repository at https://github.com/docker/docker/. 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
+    $ docker ps --format '{{.ID}}\t {{.Status}} {{.Names}} {{.Command}}' 
72
+    83fc1e842599     Up 2 days my-service.1.9jn59qzn7nbc3m0zt1hij12xs "top"
73
+    ```
74
+
75
+### Network plugins
76
+
77
+In this example, a global scope network plugin is installed on both the 
78
+swarm manager and worker. A service is created with replicated instances
79
+using the installed plugin. We will observe how the availability of the 
80
+plugin determines network creation and container scheduling.
81
+
82
+Note that node1 is the manager and node2 is the worker.
83
+
84
+
85
+1. Install a global scoped network plugin on both manager and worker. On node1 
86
+   and node2:
87
+
88
+    ```bash
89
+    $ docker plugin install bboreham/weave2
90
+    Plugin "bboreham/weave2" is requesting the following privileges:
91
+    - network: [host]
92
+    - capabilities: [CAP_SYS_ADMIN CAP_NET_ADMIN]
93
+    Do you grant the above permissions? [y/N] y
94
+    latest: Pulling from bboreham/weave2
95
+    7718f575adf7: Download complete
96
+    Digest: sha256:2780330cc15644b60809637ee8bd68b4c85c893d973cb17f2981aabfadfb6d72
97
+    Status: Downloaded newer image for bboreham/weave2:latest
98
+    Installed plugin bboreham/weave2
99
+    ```
100
+
101
+2. Create a network using plugin on manager. On node1:
102
+
103
+    ```bash
104
+    $ docker network create --driver=bboreham/weave2:latest globalnet
105
+
106
+    $ docker network ls
107
+    NETWORK ID          NAME                DRIVER                   SCOPE
108
+    qlj7ueteg6ly        globalnet           bboreham/weave2:latest   swarm
109
+    ```
110
+
111
+3. Create a service on the manager and have replicas set to 8. Observe that
112
+containers get scheduled on both manager and worker.
113
+
114
+    On node 1:
115
+
116
+    ```bash
117
+    $ docker service create --network globalnet --name myservice --replicas=8 mrjana/simpleweb simpleweb
118
+w90drnfzw85nygbie9kb89vpa
119
+    ```
120
+
121
+    ```bash
122
+    $ docker ps
123
+    CONTAINER ID        IMAGE                                                                                      COMMAND             CREATED             STATUS              PORTS               NAMES
124
+    87520965206a        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         5 seconds ago       Up 4 seconds                            myservice.4.ytdzpktmwor82zjxkh118uf1v
125
+    15e24de0f7aa        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         5 seconds ago       Up 4 seconds                            myservice.2.kh7a9n3iauq759q9mtxyfs9hp
126
+    c8c8f0144cdc        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         5 seconds ago       Up 4 seconds                            myservice.6.sjhpj5gr3xt33e3u2jycoj195
127
+    2e8e4b2c5c08        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         5 seconds ago       Up 4 seconds                            myservice.8.2z29zowsghx66u2velublwmrh
128
+    ```
129
+
130
+    On node 2:
131
+
132
+    ```bash
133
+    $ docker ps
134
+    CONTAINER ID        IMAGE                                                                                      COMMAND             CREATED             STATUS                  PORTS               NAMES
135
+    53c0ae7c1dae        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         2 seconds ago       Up Less than a second                       myservice.7.x44tvvdm3iwkt9kif35f7ykz1
136
+    9b56c627fee0        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         2 seconds ago       Up Less than a second                       myservice.1.x7n1rm6lltw5gja3ueikze57q
137
+    d4f5927ba52c        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         2 seconds ago       Up 1 second                                 myservice.5.i97bfo9uc6oe42lymafs9rz6k
138
+    478c0d395bd7        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         2 seconds ago       Up Less than a second                       myservice.3.yr7nkffa48lff1vrl2r1m1ucs
139
+    ```
140
+
141
+4. Scale down the number of instances. On node1:
142
+
143
+    ```bash
144
+    $ docker service scale myservice=0
145
+    myservice scaled to 0
146
+    ```
147
+
148
+5. Disable and uninstall the plugin on the worker. On node2:
149
+
150
+    ```bash
151
+    $ docker plugin rm -f bboreham/weave2
152
+    bboreham/weave2
153
+    ```
154
+
155
+6. Scale up the number of instances again. Observe that all containers are
156
+scheduled on the master and not on the worker, because the plugin is not available on the worker anymore.
157
+
158
+    On node 1:
159
+
160
+    ```bash
161
+    $ docker service scale myservice=8
162
+    myservice scaled to 8
163
+    ```
164
+
165
+    ```bash
166
+    $ docker ps
167
+    CONTAINER ID        IMAGE                                                                                      COMMAND             CREATED             STATUS              PORTS               NAMES
168
+    cf4b0ec2415e        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         39 seconds ago      Up 36 seconds                           myservice.3.r7p5o208jmlzpcbm2ytl3q6n1
169
+    57c64a6a2b88        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         39 seconds ago      Up 36 seconds                           myservice.4.dwoezsbb02ccstkhlqjy2xe7h
170
+    3ac68cc4e7b8        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         39 seconds ago      Up 35 seconds                           myservice.5.zx4ezdrm2nwxzkrwnxthv0284
171
+    006c3cb318fc        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         39 seconds ago      Up 36 seconds                           myservice.8.q0e3umt19y3h3gzo1ty336k5r
172
+    dd2ffebde435        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         39 seconds ago      Up 36 seconds                           myservice.7.a77y3u22prjipnrjg7vzpv3ba
173
+    a86c74d8b84b        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         39 seconds ago      Up 36 seconds                           myservice.6.z9nbn14bagitwol1biveeygl7
174
+    2846a7850ba0        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         39 seconds ago      Up 37 seconds                           myservice.2.ypufz2eh9fyhppgb89g8wtj76
175
+    e2ec01efcd8a        mrjana/simpleweb@sha256:317d7f221d68c86d503119b0ea12c29de42af0a22ca087d522646ad1069a47a4   "simpleweb"         39 seconds ago      Up 38 seconds                           myservice.1.8w7c4ttzr6zcb9sjsqyhwp3yl
176
+    ```
177
+
178
+    On node 2:
179
+
180
+    ```bash
181
+    $ docker ps
182
+    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
183
+    ```