Browse code

Rewrites to Developing Plugins topic

Signed-off-by: Misty Stanley-Jones <misty@docker.com>

Misty Stanley-Jones authored on 2016/10/21 03:12:02
Showing 1 changed files
... ...
@@ -1,51 +1,54 @@
1 1
 ---
2
-aliases: [
3
-"/engine/extend/"
4
-]
5
-title: "Managed plugin system"
6
-description: "How develop and use a plugin with the managed plugin system"
7
-keywords: ["API, Usage, plugins, documentation, developer"]
8
-advisory: "experimental"
2
+advisory: experimental
3
+aliases:
4
+- /engine/extend/
5
+description: Develop and use a plugin with the managed plugin system
6
+keywords:
7
+- API, Usage, plugins, documentation, developer
8
+title: Managed plugin system
9 9
 ---
10 10
 
11
+<!-- This file is maintained within the docker/docker Github
12
+     repository at https://github.com/docker/docker/. Make all
13
+     pull requests against that repo. If you see this file in
14
+     another repository, consider it read-only there, as it will
15
+     periodically be overwritten by the definitive file. Pull
16
+     requests which include edits to this file in other repositories
17
+     will be rejected.
18
+-->
19
+
11 20
 # Docker Engine managed plugin system
12 21
 
13 22
 This document describes the plugin system available today in the **experimental
14 23
 build** of Docker 1.12:
15 24
 
16
-* [How to operate an existing plugin](#how-to-operate-a-plugin)
17
-* [How to develop a plugin](#how-to-develop-a-plugin)
18
-
19
-Unlike the legacy plugin system, you now manage plugins using Docker Engine:
25
+* [Installing and using a plugin](index.md#installing-and-using-a-plugin)
26
+* [Developing a plugin](index.md#developing-a-plugin)
20 27
 
21
-* install plugins
22
-* start plugins
23
-* stop plugins
24
-* remove plugins
28
+Docker Engine's plugins system allows you to install, start, stop, and remove
29
+plugins using Docker Engine. This mechanism is currently only available for
30
+volume drivers, but more plugin driver types will be available in future releases.
25 31
 
26
-The current Docker Engine plugin system only supports volume drivers. We are
27
-adding more plugin driver types in the future releases.
32
+For information about the legacy plugin system available in Docker Engine 1.12
33
+and earlier, see [Understand legacy Docker Engine plugins](legacy_plugins.md).
28 34
 
29
-For information on Docker Engine plugins generally available in Docker Engine
30
-1.12 and earlier, refer to [Understand legacy Docker Engine plugins](legacy_plugins.md).
35
+## Installing and using a plugin
31 36
 
32
-## How to operate a plugin
37
+Plugins are distributed as Docker images and can be hosted on Docker Hub or on
38
+a private registry.
33 39
 
34
-Plugins are distributed as Docker images, so develpers can host them on Docker
35
-Hub or on a private registry.
40
+To install a plugin, use the `docker plugin install` command, which pulls the
41
+plugin from Docker hub or your private registry, prompts you to grant
42
+permissions or capabilities if necessary, and enables the plugin.
36 43
 
37
-You install the plugin using a single command: `docker plugin install <PLUGIN>`.
38
-The `plugin install` command pulls the plugin from the Docker Hub or private
39
-registry. If necessary the CLI prompts you to accept any privilege requriements.
40
-For example the plugin may require access to a device on the host system.
41
-Finally it enables the plugin.
44
+To check the status of installed plugins, use the `docker plugin ls` command.
45
+Plugins that start successfully are listed as enabled in the output.
42 46
 
43
-Run `docker plugin ls` to check the status of installed plugins. The Engine
44
-markes plugins that are started without issues as `ENABLED`.
47
+After a plugin is installed, you can use it as an option for another Docker
48
+operation, such as creating a volume.
45 49
 
46
-After you install a plugin, the plugin behavior is the same as legacy plugins.
47
-The following example demonstrates how to install the `sshfs` plugin and use it
48
-to create a volume.
50
+In the following example, you install the `sshfs` plugin, verify that it is
51
+enabled, and use it to create a volume.
49 52
 
50 53
 1.  Install the `sshfs` plugin.
51 54
 
... ...
@@ -60,11 +63,12 @@ to create a volume.
60 60
     vieux/sshfs
61 61
     ```
62 62
 
63
-    The plugin requests 2 privileges, the `CAP_SYS_ADMIN` capability to be able
64
-    to do mount inside the plugin and `host networking`.
63
+    The plugin requests 2 privileges:
64
+    - It needs access to the `host` network.
65
+    - It needs the `CAP_SYS_ADMIN` capability, which allows the plugin to run
66
+    the `mount` command.
65 67
 
66
-2.  Check for a value of `true` the `ENABLED` column to verify the plugin
67
-started without error.
68
+2.  Check that the plugin is enabled in the output of `docker plugin ls`.
68 69
 
69 70
     ```bash
70 71
     $ docker plugin ls
... ...
@@ -74,6 +78,8 @@ started without error.
74 74
     ```
75 75
 
76 76
 3.  Create a volume using the plugin.
77
+    This example mounts the `/remote` directory on host `1.2.3.4` into a
78
+    volume named `sshvolume`. This volume can now be mounted into containers.
77 79
 
78 80
     ```bash
79 81
     $ docker volume create \
... ...
@@ -83,39 +89,39 @@ started without error.
83 83
 
84 84
     sshvolume
85 85
     ```
86
-
87
-4.  Use the volume `sshvolume`.
86
+4.  Verify that the volume was created successfully.
88 87
 
89 88
     ```bash
90
-    $ docker run -v sshvolume:/data busybox ls /data
89
+    $ docker volume ls
91 90
 
92
-    <content of /remote on machine 1.2.3.4>
91
+    DRIVER              NAME
92
+    vieux/sshfs         sshvolume
93 93
     ```
94 94
 
95
-5.  Verify the plugin successfully created the volume.
95
+5.  Start a container that uses the volume `sshvolume`.
96 96
 
97 97
     ```bash
98
-    $ docker volume ls
98
+    $ docker run -v sshvolume:/data busybox ls /data
99 99
 
100
-    DRIVER              VOLUME NAME
101
-    vieux/sshfs         sshvolume
100
+    <content of /remote on machine 1.2.3.4>
102 101
     ```
103 102
 
104
-    You can stop a plugin with the `docker plugin disable`
105
-    command or remove a plugin with `docker plugin remove`.
106
-
107
-See the [command line reference](../reference/commandline/index.md) for more
108
-information.
103
+To disable a plugin, use the `docker plugin disable` command. To completely
104
+remove it, use the `docker plugin remove` command. For other available
105
+commands and options, see the
106
+[command line reference](../reference/commandline/index.md).
109 107
 
110
-## How to develop a plugin
108
+## Developing a plugin
111 109
 
112
-Plugin creation is currently a manual process. We plan to add automation in a
113
-future release with a command such as `docker plugin build`.
110
+Currently, there are no CLI commands available to help you develop a plugin.
111
+This is expected to change in a future release. The manual process for creating
112
+plugins is described in this section.
114 113
 
115
-This section describes the format of an existing enabled plugin. You have to
116
-create and format the plugin files by hand.
114
+### Plugin location and files
117 115
 
118
-Plugins are stored in `/var/lib/docker/plugins`. For instance:
116
+Plugins are stored in `/var/lib/docker/plugins`. The `plugins.json` file lists
117
+each plugin's configuration, and each plugin is stored in a directory with a
118
+unique identifier.
119 119
 
120 120
 ```bash
121 121
 # ls -la /var/lib/docker/plugins
... ...
@@ -126,9 +132,12 @@ drwxr-xr-x  3 root root 4096 Aug  8 17:56 cd851ce43a403
126 126
 -rw-------  1 root root 2107 Aug  8 18:03 plugins.json
127 127
 ```
128 128
 
129
-`plugins.json` is an inventory of all installed plugins. For example:
129
+### Format of plugins.json
130 130
 
131
-```bash
131
+The `plugins.json` is an inventory of all installed plugins. This example shows
132
+a `plugins.json` with a single plugin installed.
133
+
134
+```json
132 135
 # cat plugins.json
133 136
 {
134 137
   "cd851ce43a403": {
... ...
@@ -179,7 +188,10 @@ drwxr-xr-x  3 root root 4096 Aug  8 17:56 cd851ce43a403
179 179
 }
180 180
 ```
181 181
 
182
-Each folder represents a plugin. For example:
182
+### Contents of a plugin directory
183
+
184
+Each directory within `/var/lib/docker/plugins/` contains a `rootfs` directory
185
+and two JSON files.
183 186
 
184 187
 ```bash
185 188
 # ls -la /var/lib/docker/plugins/cd851ce43a403
... ...
@@ -189,28 +201,34 @@ drwx------ 19 root root 4096 Aug  8 17:56 rootfs
189 189
 -rw-------  1 root root  347 Aug  8 17:56 manifest.json
190 190
 ```
191 191
 
192
-`rootfs` represents the root filesystem of the plugin. In this example, it was
193
-created from a Dockerfile as follows:
192
+#### The rootfs directory
193
+The `rootfs` directory represents the root filesystem of the plugin. In this
194
+example, it was created from a Dockerfile:
194 195
 
195
->**Note:** `/run/docker/plugins` is mandatory for docker to communicate with
196
-the plugin._
196
+>**Note:** The `/run/docker/plugins` directory is mandatory for docker to communicate with
197
+the plugin.
197 198
 
198 199
 ```bash
199 200
 $ git clone https://github.com/vieux/docker-volume-sshfs
200 201
 $ cd docker-volume-sshfs
201 202
 $ docker build -t rootfs .
202 203
 $ id=$(docker create rootfs true) # id was cd851ce43a403 when the image was created
203
-$ mkdir -p /var/lib/docker/plugins/$id/rootfs
204
-$ docker export "$id" | tar -x -C /var/lib/docker/plugins/$id/rootfs
204
+$ sudo mkdir -p /var/lib/docker/plugins/$id/rootfs
205
+$ sudo docker export "$id" | sudo tar -x -C /var/lib/docker/plugins/$id/rootfs
206
+$ sudo chgrp -R docker /var/lib/docker/plugins/
205 207
 $ docker rm -vf "$id"
206 208
 $ docker rmi rootfs
207 209
 ```
208 210
 
209
-`manifest.json` describes the plugin and `plugin-config.json` contains some
210
-runtime parameters. [See the Plugins Manifest reference](manifest.md). For example:
211
+#### The manifest.json and plugin-config.json files
211 212
 
212
-```bash
213
-# cat manifest.json
213
+The `manifest.json` file describes the plugin. The `plugin-config.json` file
214
+contains runtime parameters and is only required if your plugin has runtime
215
+parameters. [See the Plugins Manifest reference](manifest.md).
216
+
217
+Consider the following `manifest.json` file.
218
+
219
+```json
214 220
 {
215 221
 	"manifestVersion": "v0",
216 222
 	"description": "sshFS plugin for Docker",
... ...
@@ -227,13 +245,15 @@ runtime parameters. [See the Plugins Manifest reference](manifest.md). For examp
227 227
 }
228 228
 ```
229 229
 
230
-In this example, you can see the plugin is a volume driver, requires the
231
-`CAP_SYS_ADMIN` capability, `host networking`, `/go/bin/docker-volume-sshfs` as
232
-entrypoint and is going to use `/run/docker/plugins/sshfs.sock` to communicate
233
-with the Docker Engine.
230
+This plugin is a volume driver. It requires a `host` network and the
231
+`CAP_SYS_ADMIN` capability. It depends upon the `/go/bin/docker-volume-sshfs`
232
+entrypoint and uses the `/run/docker/plugins/sshfs.sock` socket to communicate
233
+with Docker Engine.
234 234
 
235
-```bash
236
-# cat plugin-config.json
235
+
236
+Consider the following `plugin-config.json` file.
237
+
238
+```json
237 239
 {
238 240
   "Devices": null,
239 241
   "Args": null,
... ...
@@ -242,26 +262,42 @@ with the Docker Engine.
242 242
 }
243 243
 ```
244 244
 
245
-This plugin doesn't require runtime parameters.
245
+This plugin has no runtime parameters.
246
+
247
+Each of these JSON files is included as part of `plugins.json`, as you can see
248
+by looking back at the example above. After a plugin is installed, `manifest.json`
249
+is read-only, but `plugin-config.json` is read-write, and includes all runtime
250
+configuration options for the plugin.
251
+
252
+### Creating the plugin
253
+
254
+Follow these steps to create a plugin:
246 255
 
247
-Both `manifest.json` and `plugin-config.json` are part of the `plugins.json`.
248
-`manifest.json` is read-only and `plugin-config.json` is read-write.
256
+1. Choose a name for the plugin. Plugin name uses the same format as images,
257
+   for example: `<repo_name>/<name>`.
249 258
 
250
-To summarize, follow the steps below to create a plugin:
259
+2. Create a `rootfs` and export it to `/var/lib/docker/plugins/$id/rootfs`
260
+   using `docker export`. See [The rootfs directory](#the-rootfs-directory) for
261
+   an example of creating a `rootfs`.
251 262
 
252
-0. Choose a name for the plugin. Plugin name uses the same format as images,
253
-for example: `<repo_name>/<name>`.
254
-1. Create a rootfs in `/var/lib/docker/plugins/$id/rootfs`.
255
-2. Create manifest.json file in `/var/lib/docker/plugins/$id/`.
256
-3. Create a `plugin-config.json` if needed.
257
-4. Create or add a section to `/var/lib/docker/plugins/plugins.json`. Use
263
+3. Create a `manifest.json` file in `/var/lib/docker/plugins/$id/`.
264
+
265
+4. Create a `plugin-config.json` file if needed.
266
+
267
+5. Create or add a section to `/var/lib/docker/plugins/plugins.json`. Use
258 268
    `<user>/<name>` as “Name” and `$id` as “Id”.
259
-5. Restart the Docker Engine.
260
-6. Run `docker plugin ls`.
261
-    * If your plugin is listed as `ENABLED=true`, you can push it to the
262
-    registry.
263
-    * If the plugin is not listed or if `ENABLED=false`, something went wrong.
264
-    Check the daemon logs for errors.
265
-7. If you are not already logged in, use `docker login` to authenticate against
266
-   a registry.
267
-8. Run `docker plugin push <repo_name>/<name>` to push the plugin.
269
+
270
+6. Restart the Docker Engine service.
271
+
272
+7. Run `docker plugin ls`.
273
+    * If your plugin is enabled, you can push it to the
274
+      registry.
275
+    * If the plugin is not listed or is disabled, something went wrong.
276
+      Check the daemon logs for errors.
277
+
278
+8. If you are not already logged in, use `docker login` to authenticate against
279
+   the registry so that you can push to it.
280
+
281
+9. Run `docker plugin push <repo_name>/<name>` to push the plugin.
282
+
283
+The plugin can now be used by any user with access to your registry.